jQuery.expr[':'].Contains = function(a, i, m) {
    return jQuery(a).text().toLowerCase().indexOf(m[3].toLowerCase()) >= 0;
};
//返回页面最大的z-index值
$.maxZIndex = $.fn.maxZIndex = function(opt) {
    var def = {
        inc: 10,
        group: "*"
    };
    $.extend(def, opt);
    var zmax = 0;
    $(def.group).each(function() {
        var cur = parseInt($(this).css('z-index'));
        zmax = cur > zmax ? cur : zmax;
    });
    if (!this.jquery)
        return zmax;

    return this.each(function() {
        zmax += def.inc;
        $(this).css("z-index", zmax);
    });
};


(function($){
	$.extend($.fn,{
		overlay:function(setting){
			var ps = $.extend({
				renderTo:$(document.body),
				cls:"",
				backgroundColor:'#000',
				opacity:'0.5',
				zIndex:'999'
			},setting);
			ps.renderTo = (typeof ps.renderTo == 'string' ? $(ps.renderTo) : ps.renderTo);
			var overlayDiv = $("<div></div>");
			if(ps.cls != ''){
				overlayDiv.addClass(ps.cls);
			}else{
				overlayDiv.css("background",ps.backgroundColor);
			}			
			
			
			resizeTO();
			overlayDiv.appendTo(ps.renderTo);
			$(window).resize(function(){
				resizeTO();
			})			
			function resizeTO(){
				var renderWidth = ps.renderTo.outerWidth();
				var renderHeight = ps.renderTo.outerHeight();
				var renderPosition = ps.renderTo.position();
				overlayDiv.width(renderWidth);
				overlayDiv.height(renderHeight);
				overlayDiv.css({'z-index':ps.zIndex,opacity:ps.opacity,position:'absolute',top:renderPosition.top,left:renderPosition.left});
			}
			return overlayDiv;
		},
		destroy:function(){
			this.remove();
		},
		minimize:function(){
			this.hide();
		},
		restore:function(){
			this.show();
		},
		setZindex:function(zIndex){
			this.css({"z-index":zIndex});
		}
	})
})(jQuery);

/*
 * jQuery button 0.1
 * http://www.bsweb.com.cn
 * 需要库文件
 * 		jquery-ui.js
 */
(function($,undefined){
	$.widget("ui.button",{
		options:{
			id:null,
			disabled:false,
			plain:false,
			text:'',
			iconCls:null,
			handler:null
		},
		_create:function(){
			var text = "";
			if(this.options.text == ""){
				this.options.text = this.element.html();
			}			
			var buttonCtx = $("<span class='bs-button-left'><span class='bs-button-text'></span></span>");			
			this.element.html("").append(buttonCtx).addClass("bs-button");
			this.element.find(".bs-button-text").html(this.options.text);
		},
		_init:function(){
			var _self = this;			
			if(this.options.id != null){
				this.element.attr("id",this.options.id);
			}		
		
			if(this.options.plain == true){
				this.element.addClass("bs-button-plain").css("height","22px");
			}
			this.element.hover(function(){						
				if(_self.options.plain != true){
					$(this).addClass("bs-button-hover");
					$(this).find(".bs-button-left").addClass("bs-button-left-hover");
				}
			},function(){
				if(_self.options.plain != true){
					$(this).removeClass("bs-button-hover");
					$(this).find(".bs-button-left").removeClass("bs-button-left-hover");
				}
			})
			if(this.options.iconCls != null){				
				this.element.find(".bs-button-text").addClass(this.options.iconCls);
				if (this.options.text == "") {
					this.element.find(".bs-button-text").css("padding-left", "16px");
				}else{
					this.element.find(".bs-button-text").css("padding-left", "20px");
				}
			}
			
			if($.isFunction(_self.options.handler)){				
				this.element.click(_self.options.handler);
			}
			
			if(this.options.disabled == true){
				this.element.unbind("click");
				this.element.addClass("bs-button-disable");
			}
		},
		disable:function(){
			var _self = this;
			this.options.disabled = true;			
			this.element.addClass("bs-button-disable");
			this.element.unbind("click");
		},
		enable:function(){
			var _self = this;
			this.options.disabled = false;
			this.element.unbind("click");
			if($.isFunction(this.options.handler)){
				_self.element.click(_self.options.handler);
			}			
			this.element.removeClass("bs-button-disable");
		}
	})
})(jQuery);

/*
 * jQuery Toolbar 0.1
 * http://www.bsweb.com.cn
 * 需要库文件
 * 		jquery-ui.js
 * 		jquery-button.js
 */
(function($,undefined){
	$.widget("ui.toolbar",{
		options:{
			items:[]
		},
		_create:function(){
			this.toolbarPanel = this.element;
			this.toolbarPanel.append("<div class='toolbar-clearboth'/>");
		},
		_init:function(){
			var opts = this.options;
			if(opts.items.length > 0){
				for(var i = 0;i < opts.items.length;i++){
					this.addToolComponent(opts.items[i]);
				}
			}
		},
		_rsButton:function(btnObj){
			if($.trim(btnObj.type == '')){
				btnObj.typetype = "button";
			}
			if($.trim(btnObj.text) == ""){
				btnObj.text = "";
			}
			var toolBtn = "";
			if(btnObj.text == "-"){
				toolBtn = $("<div class='tool-separator'/>");
			}
			if(btnObj.type == "button"){
				toolBtn = $("<a>").button(btnObj);
				toolBtn.css("float","left");
//				toolBtn = "<a style='float:left;' href='javascript:void(0)' class='btn'>"+
//						  "<span class='btn-left'><span style='padding-left:20px;' class='btn-text'></span></span></a>";
//				toolBtn = $(toolBtn);
//				toolBtn.children("span").children("span").html(btnObj.text);
//				if($.trim(btnObj.iconCls) != ""){
//					toolBtn.children("span").children("span").addClass(btnObj.iconCls);
//				}
//				if($.isFunction(btnObj.handler)){
//					toolBtn.click(btnObj.handler);
//				}
			}
			return toolBtn;
		},
		addToolComponent:function(btnObj){
			if($.trim(btnObj.type == '')){
				btnObj.type = "button";
			}
			var toolCtx = "";
			
			if(btnObj.type == 'compGroup'){
				if(btnObj.items == undefined || btnObj.items == null || btnObj.items.length < 1){
					return;
				}
				toolCtx = $("<div />");
				if($.trim(btnObj.ctxCls) != ''){
					toolCtx.addClass(btnObj.ctxCls);
				}
				for(var i = 0;i < btnObj.items.length;i++){
					var tmpBtn = this._rsButton(btnObj.items[i]);
					
					toolCtx.append(tmpBtn);
				}
				toolCtx.append("<div class='toolbar-clearboth'/>");
			}else{
				toolCtx = this._rsButton(btnObj);
			}
			this.toolbarPanel.addClass("panel-toolbar");
			
			this.toolbarPanel.children(".toolbar-clearboth").before(toolCtx);
		},
		test:function(){
			//alert("uuuuu");
		}
	})
})(jQuery);

/*
 * jQuery Panel 0.1
 * http://www.bsweb.com.cn
 * 需要库文件
 * 		jquery-ui.js
 * 		buss.toolbar.js
 */
(function($,undefined){
	$.widget("ui.panel",{
		options:{
			title:null,					//Panel标题文本			
			width:'auto',				//Panel宽度
			height:'auto',				//Panel高度			
			iconCls:null,				//Panel图片Class
			headerCls:null,		//Panel的Title的Class
			bodyCls:null,		//Panel内容Class			
			content:false,				    //Panel的内容容器
			header:false,					//是否需要Title栏
			closable:false,					//是否需要Close按钮
			minimizable:false,				//是否需要最下化按钮
			collapsible:false,				//是否需要收缩按钮
			bodyContent:'body',
			isDialog:false,					//是否弹出窗口
			iframe:false,
			topTools:[],					//Panel上面工具栏
			bottomTools:[],					//Panel下面工具栏
			loadUrl:null,					//加载内容到Panel
			laodParams:null,				//加载内容参数
			loadingMessage:'Loading...',	//加载数据未完成时显示的信息
			onLoad:function(){},			//加载完成触发的事件
			onBeforeOpen:function(){},		//在打开Panel之前触发的事件
			onOpen:function(){},			//在打开Panel之后触发的事件
			onBeforeClose:function(){},		//Panel关闭之前触发
			onClose:function(){},			//在关闭Panel之后触发的事件
			onBeforeDestroy:function(){},	//在销毁Panel之前触发的事件
			onDestroy:function(){},			//在销毁Panel之后触发的事件
			onBeforeMinimize:function(){},	//最小化Panel之后触发的事件
			onMinimize:function(){},		//最小化Panel之后触发的事件
			onBeforeCollapse:function(){},	//Panel收缩之前触发的事件
			onCollapse:function(){},		//Panel收缩之后触发的事件
			onBeforeExpand:function(){},		//Panel展开之前触发的事件
			onExpand:function(){},			//Panel展开之后触发的事件
			onBeforeRestore:function(){},	//
			onRestore:function(){}
		},
		/**
		 * 创建Panel所用的模板
		 */
		_create:function(){
			this._createPanel();
		},
		_createPanel:function(){
			var panelHeaderTpl = "<div class='buss-panel-header'><span class='buss-panel-with-icon'>My Panel</span>"+
				      "<div class='buss-panel-icon'/><div class='buss-panel-tool'>"+
					  "<div class='buss-panel-tool-close'/><div class='buss-panel-tool-min'/><div class='buss-panel-tool-collapse'/>" +
					  "</div></div>";//buss-panel-top-toolbar-left
			var topbar = "";
				if(this.options.isDialog){
					topbar = "<table class='buss-panel-toolbar-border' cellspacing='0' cellpadding='0'><tbody><tr><td class='buss-panel-top-toolbar-left'></td><td><div class='buss-panel-top-toolbar'></div></td><td class='buss-panel-top-toolbar-right'></td></tr></table>";				
				}else{
					topbar = "<div class='buss-panel-top-toolbar'></div>";
				}
			var panelBodyTpl = "<div class='buss-panel-body'>" +
					  topbar +  
					  "<div class='buss-panel-body-content'></div>" +
					  "<div class='buss-panel-bottom-toolbar'></div>"  
					  "</div>";
			this.bodyContent = this.element.html();
			this.element.html("");
			this.panelHeaderTemplate = $(panelHeaderTpl);
			this.panelBodyTemplate = $(panelBodyTpl);
			
			
			this.panelTemplate = this.element.append(this.panelHeaderTemplate).append(this.panelBodyTemplate).addClass("buss-panel");
			if(this.panelTemplate.parent().attr("tagName") == undefined){
				this.panelTemplate.appendTo($("body"));
			}
		},
		/**
		 * 初始化Panel信息
		 */
		_init:function(){
			this._initPanel();
		},		
		_initPanel:function(){
			var opts = this.options;
			var _width = opts.width;
			var _height = opts.height;
			
			if($.isFunction(opts.onBeforeOpen)){
				if(opts.onBeforeOpen.call(this.panelTemplate) == false) return;
			}
			
			this._setHeaderTool();
			
			if (isNaN(_width)){
				_width = 'auto';
			}
			
			var _tmpWidth = this.element.css("width");	
			_tmpWidth = _tmpWidth.substring(0,_tmpWidth.indexOf("px"));
			if(_width == 'auto'){
				_width = _tmpWidth;
			}		

			_width = parseInt(_width);
			if(isNaN(_height)){
				_height = 'auto';
			}
			
			if(this.element.css("height")){
				var _tmpHeight = this.element.css("height");
				_tmpHeight = _tmpHeight.substring(0,_tmpHeight.indexOf("px"));
				if(_height == 'auto'){
					_height = _tmpHeight;
				}
			}
			_height = parseInt(_height);

			
			this.panelTemplate.css({width:_width,height:_height,display:'block'});
			if(this.options.isDialog){
				//alert(this.panelBodyTemplate.find("buss-panel-body-content").html());
				this.panelBodyTemplate.find(".buss-panel-body-content").addClass("buss-panel-body-border");
				this.panelBodyTemplate.find(".buss-panel-toolbar-border").width(_width - 2);
			}
			this.panelTemplate.find(".buss-panel-header").css("display","block");
			/*if($.browser.msie){
				//this.panelTemplate.find(".buss-panel-header").width(_width - 12);
				this.panelTemplate.find(".buss-panel-header").css("display","block");
			}else{
				//this.panelTemplate.find(".buss-panel-header").width(_width - 12);
				this.panelTemplate.find(".buss-panel-header").css("width","100%");
			}*/
			
			var topToolHeight = 0;
			if(opts.topTools.length < 1){
				this.panelBodyTemplate.find(".buss-panel-top-toolbar").hide();
				topToolHeight = 0;
			}else{
				this.panelBodyTemplate.find(".buss-panel-top-toolbar").show();
				this.panelBodyTemplate.find(".buss-panel-top-toolbar").toolbar({
					items:opts.topTools
				})
				topToolHeight = this.panelBodyTemplate.find(".buss-panel-top-toolbar").outerHeight(true);
			}
			var bottomToolHeight = 0;
			if(opts.bottomTools.length < 1){
				this.panelBodyTemplate.find(".buss-panel-bottom-toolbar").hide();
				bottomToolHeight = 0;
			}else{
				this.panelBodyTemplate.find(".buss-panel-bottom-toolbar").show();
				this.panelBodyTemplate.find(".buss-panel-bottom-toolbar").toolbar({
					items:opts.bottomTools
				})
				bottomToolHeight = this.panelBodyTemplate.find(".buss-panel-bottom-toolbar").outerHeight(true);
			}
			
			//var topToolHeight = this.panelBodyTemplate.find(".buss-panel-top-toolbar").outerHeight(true)==null ? 0 :this.panelBodyTemplate.find(".buss-panel-top-toolbar").outerHeight(true);
			
			//var bottomToolHeight = this.panelBodyTemplate.find(".buss-panel-bottom-toolbar").outerHeight(true) == null ? 0 :this.panelBodyTemplate.find(".buss-panel-bottom-toolbar").outerHeight(true);		
			
			
			var _bodyHeight = this.element.outerHeight() - this.panelHeaderTemplate.outerHeight(true) - topToolHeight - bottomToolHeight;
			
			//alert(_bodyHeight);
			
			//if($.browser.msie){
			//	_bodyHeight -= 23;
			//}
			
			this.panelBodyTemplate.find(".buss-panel-body-content").html(this.bodyContent);
			this.panelBodyTemplate.find(".buss-panel-body-content").addClass(function(){
				return opts.bodyCls == null ? "" : opts.bodyCls;
			});
			var spacHeight = this.panelBodyTemplate.find(".buss-panel-body-content").outerHeight() - this.panelBodyTemplate.find(".buss-panel-body-content").height();
			this.panelBodyTemplate.find(".buss-panel-body-content").height(_bodyHeight - spacHeight - 3);
			
			if($.isFunction(opts.onOpen)){
				opts.onOpen.call(this.panelTemplate);
			}
		},
		setTitle:function(title){
			if (title != null){
				this.panelHeaderTemplate.find(".buss-panel-with-icon").html(title);
			}
		},
		setBodyHeight:function(height){
			var _bodyHeight = this.panelBodyTemplate.find(".buss-panel-body-content").height();
			var tmpHeight = height - _bodyHeight;
			this.panelBodyTemplate.find(".buss-panel-body-content").height(height);
			this.panelTemplate.height(this.panelTemplate.height() + tmpHeight);
		},
		loadPage:function(loadUrl,loadParams,iframe,onLoad){
			var opts = this.options;
			var _self = this;
			if($.trim(loadUrl) != ''){
				opts.loadUrl = loadUrl;
			}
			if($.trim(loadParams) != ''){
				opts.loadParams = loadParams;
			}
			if($.isFunction(onLoad)){
				opts.onLoad = onLoad;
			}
			if(iframe != undefined && iframe != null){
				opts.iframe = iframe;
			}
			if(opts.loadUrl == null || opts.loadUrl == ""){
				return;
			}			
			_self._load()
		},
		_load:function(){
			var opts = this.options;		
			var _self = this;
			if (opts.iframe == false) {
				
				this.panelBodyTemplate.find(".buss-panel-body-content").load(opts.loadUrl, opts.loadParams, opts.onLoad);
			}else{
				var borderHeight = this.panelBodyTemplate.find(".buss-panel-body-content").outerHeight() - this.panelBodyTemplate.find(".buss-panel-body-content").height();
				var borderWidth = this.panelBodyTemplate.find(".buss-panel-body-content").outerWidth() - this.panelBodyTemplate.find(".buss-panel-body-content").width();
				var iframeVar = $("<iframe frameborder='no'></iframe>")
				iframeVar.height(this.panelBodyTemplate.find(".buss-panel-body-content").height() - borderHeight - 1);
				iframeVar.width(this.panelBodyTemplate.find(".buss-panel-body-content").width() - borderWidth - 1);
				iframeVar.attr("src",opts.loadUrl);
				iframeVar.load(opts.onLoad);
				this.panelBodyTemplate.find(".buss-panel-body-content").html(iframeVar);
			}
		},
		_setHeaderTool:function(){
			var opts = this.options;
			var _self = this;
			if(opts.header == false){
				this.panelHeaderTemplate.remove();
				return;
			}
			this.setTitle(opts.title);
			if(opts.closable == false){
				this.panelHeaderTemplate.find(".buss-panel-tool-close").remove();
			}else{
				this.panelHeaderTemplate.find(".buss-panel-tool-close").bind("click",function(){
					_self.destroy(_self);
				});
			}
			if(opts.minimizable == false){
				this.panelHeaderTemplate.find(".buss-panel-tool-min").remove();				
			}else{
				this.panelHeaderTemplate.find(".buss-panel-tool-min").bind("click",function(){
					_self.minimize(_self);
				})
			}
			if(opts.collapsible == false){
				this.panelHeaderTemplate.find(".buss-panel-tool-collapse").remove();
			}else{
				this.panelHeaderTemplate.find(".buss-panel-tool-collapse").bind("click",function(){
					if (opts.collapsibled == undefined || opts.collapsibled == false) {
						_self.collapsible();
					}else{
						_self.expand();
					}
				})
			}
			if (opts.iconCls == null){
				this.panelHeaderTemplate.find(".buss-panel-with-icon").css('padding-left','0');
			}else{
				this.panelHeaderTemplate.find(".buss-panel-icon").addClass(opts.iconCls);
			}
		},
		collapsible:function(target){
			var _self = target != null && target != undefined ? target : this;
			var opts = _self.options;
			if($.isFunction(opts.onBeforeCollapse)){
				if(opts.onBeforeCollapse.call(_self.panelTemplate) == false) return;
			}
			_self.panelTemplate.find(".buss-panel-body").hide();
			opts.collapsibled = true;
			if($.isFunction(opts.onCollapse)){
				opts.onCollapse.call(_self.panelTemplate);
			}
		},
		expand:function(target){
			var _self = target != null && target != undefined ? target : this;
			var opts = _self.options;
			if($.isFunction(opts.onBeforeExpand)){
				if(opts.onBeforeExpand.call(_self.panelTemplate) == false) return;
			}
			_self.panelTemplate.find(".buss-panel-body").show();
			opts.collapsibled = false;
			if($.isFunction(opts.onCollapse)){
				opts.onExpand.call(_self.panelTemplate);
			}
		},
		minimize:function(target){
			this._minimize(target);
		},
		_minimize:function(target){
			var _self = target != null && target != undefined ? target : this;
			var opts = _self.options;
			if(opts.minimized == true){
				return;
			}
			if($.isFunction(opts.onBeforeMinimize)){
				if(opts.onBeforeMinimize.call(_self.panelTemplate) == false) return;
			}
			_self.panelTemplate.hide();
			opts.minimized = true;
			if($.isFunction(opts.onMinimize)){
				opts.onMinimize.call(_self.panelTemplate);
			}
		},
		restore:function(target){			
			this._restore(target);
		},
		_restore:function(target){
			var _self = target != null && target != undefined ? target : this;
			var opts = _self.options;
			if(opts.minimized != true){
				return;
			}
			if($.isFunction(opts.onBeforeRestore)){
				if(opts.onBeforeRestore.call(_self.panelTemplate) == false) return;
			}
			_self.panelTemplate.show();
			opts.minimized = false;
			if($.isFunction(opts.onRestore)){
				opts.onRestore.call(_self.panelTemplate);
			}
		},
		close:function(target){			
			this._close(target);
		},
		_close:function(target){
			var _self = target != null && target != undefined ? target : this;
			var opts = _self.options;
			if($.isFunction(opts.onBeforeRestore)){
				if(opts.onBeforeClose.call(_self.panelTemplate) == false) return;
			}
			_self.panelTemplate.hide();
			opts.minimized = true;
			if($.isFunction(opts.onRestore)){
				opts.onClose.call(_self.panelTemplate);
			}
		},
		destroy:function(target){			
			this._destroy(target);
		},
		_destroy:function(target){
			var _self = target != null && target != undefined ? target : this;
			var opts = _self.options;
			if($.isFunction(opts.onBeforeDestroy)){
				if(opts.onBeforeDestroy.call(_self.panelTemplate) == false) return;
			}
			this.element.find("*").trigger("_destroy");
			_self.panelTemplate.unbind().remove();
			if($.isFunction(opts.onDestroy)){
				opts.onDestroy.call(_self.panelTemplate);
			}
		}
	})
})(jQuery);

/**
 * 
 * @param {Object} "ui.combo"
 * @param {Object} {options:{width:'auto'
 * @param {Object} panelWidth:null
 * @param {Object} panelHeight:200
 * @param {Object} editable:true
 * @param {Object} disabled:false
 * @param {Object} required:false
 * @param {Object} topTools:[]
 * @param {Object} bottomTools:[]
 * @param {Object} selectPrev:function(
 */
(function($,undefined){
	$.widget("ui.combo",{
		options:{
			width:'auto',
			panelWidth:null,
			panelHeight:200,
			editable:true,
			disabled:false,
			required:false,
			topTools:[],
			bottomTools:[],
			selectPrev:function(){},
			selectNext:function(){},
			filter:false,
			onChange:function(newValue,oldValue){}
		},
		_create:function(){
			this.element.hide();
			var _self = this;
			this.comboSpan = $("<span class='buss-combo'/>").insertAfter(this.element);
			var input = $("<input class='buss-combo-text' type='text'/>").appendTo(this.comboSpan);
			$("<span><span class='buss-combo-arrow'></span></span>").appendTo(this.comboSpan);
			$("<input type='hidden' class='buss-combo-value'/>").appendTo(this.comboSpan);
			this.comboPanel = $("<div class='buss-combo-panel' style='position:absolute;display:block;'/>");
			var items = $("<ul style='display:block;' class='buss-combo-itempanel'></ul>");
			this.comboPanel.append(items);		
					
		},
		_init:function(){			
			var _self = this;
			var _width = this.element.outerWidth();
			if(!this.options.editable){
				this.comboSpan.find(".buss-combo-text").attr("readonly","readonly");
			}
			if(this.options.width != 'auto'){
				_width = this.options.width;
			}
			this.comboSpan.find(".buss-combo-text").css("width",_width - this.comboSpan.find(".buss-combo-arrow").outerWidth());
			var _panelWidth = 0;
			if(this.options.panelWidth == null){
				_panelWidth = _width + 2;
			}else{
				_panelWidth = this.options.panelWidth + 2;
			}
			
			this.comboPanel.panel({
				width:_panelWidth,
				height:_self.options.panelHeight,
				topTools:_self.options.topTools,
				bottomTools:_self.options.bottomTools,
				onRestore:function(){
					//alert("tt");
					var curVal = _self.comboSpan.find(".buss-combo-value").val();
				
					var curItem = _self.comboPanel.find(".buss-panel-body-content li[val="+curVal+"]");
					_self.comboPanel.find(".buss-panel-body-content ul li").removeClass("buss-combo-panel-itemsel");
					if(curItem.length > 0){
						//alert(curItem.length);
						curItem.addClass("buss-combo-panel-itemsel");
						var h = _self.comboPanel.find(".buss-panel-body-content").scrollTop() + curItem.position().top;
						h -= (curItem.outerHeight() +  _self.comboPanel.find(".buss-panel-body .buss-panel-top-toolbar").outerHeight() + _self.comboPanel.find(".buss-panel-body .buss-panel-bottom-toolbar").outerHeight());
					}
							
					_self.comboPanel.find(".buss-panel-body-content").scrollTop(h);
								
					var ulHeight = $(this).find("ul").outerHeight();
					var panelHeight = $(this).panel("option","height");
					var ctxHeight = panelHeight - _self.comboPanel.find(".buss-panel-body .buss-panel-top-toolbar").outerHeight() + _self.comboPanel.find(".buss-panel-body .buss-panel-bottom-toolbar").height();
					if(ulHeight < ctxHeight){
						$(this).panel("setBodyHeight",ulHeight);
					}else{
						$(this).panel("setBodyHeight",ctxHeight - 5);
					}
					var zIndex = parseInt(_self.comboPanel.css('z-index'));
					zIndex = isNaN(zIndex) ? 0 : zIndex;
					var maxZIndex = $.maxZIndex();
					if (maxZIndex == 0 || maxZIndex > zIndex){
						_self.comboPanel.css("z-index",maxZIndex + 1);
					}					
					_self._setPosition();
				}
			});	
			this.comboPanel.find(".buss-panel-body").addClass("buss-combo-panel-topborder");
			this.element.unbind("_destroy.buss");
			this.element.bind("_destroy.buss",function(){
				_self.comboPanel.remove();
			})
			
			this.comboPanel.panel("close");
			var zIndex = parseInt(this.comboPanel.css('z-index'));
			zIndex = isNaN(zIndex) ? 0 : zIndex;
			var maxZIndex = $.maxZIndex();
			if (maxZIndex == 0 || maxZIndex > zIndex){
				this.comboPanel.css("z-index",maxZIndex + 1);
			}			
			this.comboPanel.find(".buss-panel-body").css("border","1px solid #879faf");
			
			if (_self.options.topTools.length > 0){
				this.comboPanel.find(".buss-panel-body").css("border-top","none");
			}
			this.comboPanel.find(".buss-panel-bottom-toolbar").css("border-top","none");
			this._setPosition();
			this._bindEvents();		
			this.refresh();
		},
		refresh:function(){
			var _self = this;
			_self.comboPanel.find(".buss-panel-body-content ul").empty();
			var curSelItem = this.element.find("option[selected]");
			_self.comboSpan.find(".buss-combo-value").val(curSelItem.val());
			_self.comboSpan.find(".buss-combo-text").val(curSelItem.text());			
			_self.comboPanel.find(".buss-panel-body-content ul")
			
			this.element.children().each(function(i,o){
				var val = $(this).attr("value");
				var html = $(this).html();
				
				var li = $("<li val='"+val+"'>"+html+"</li>");
				if($(this).attr('selected')){					
					//li.attr("selected","selected");
					_self._changeValue(li);
					//alert(li.attr(selected));
				}
				li.click(function(){		
					_self._changeValue($(this));					
					_self.comboPanel.panel("close");
				})
				_self.comboPanel.find(".buss-panel-body-content ul").append(li);
			})
			
		},
		_changeValue:function(curItem){			
			
			var oldValues = this.comboSpan.find(".buss-combo-value").val();
			this.comboSpan.find(".buss-combo-value").val(curItem.attr('val'));
			this.comboSpan.find(".buss-combo-text").val(curItem.html());
			this.element.val(curItem.attr('val'));					
			this.options.onChange.call(this.element, curItem.attr('val'), oldValues);
		},
		changeValue:function(val){
			var oldValues = this.comboSpan.find(".buss-combo-value").val();
			this.comboSpan.find(".buss-combo-value").val(val);
			var text = this.element.find("option[value='"+val+"']").html();
			this.comboSpan.find(".buss-combo-text").val(text);
			this.element.val(val);					
			this.options.onChange.call(this.element, val, oldValues);
		},
		_setPosition:function(){
			var inputOffset = this.comboSpan.offset();
			var bottomGap = $(window).height() - inputOffset.top + this.comboSpan.outerHeight();
			
			if(inputOffset.top >= this.comboPanel.outerHeight() && bottomGap <= this.comboPanel.outerHeight()){
				this.options._pos = "top";
				
				var top = inputOffset.top - this.comboPanel.outerHeight() + 3;
				
				var left = inputOffset.left;		
				
				this.comboPanel.css({top:top,left:left});
				this.comboPanel.find(".buss-panel-top-toolbar").css("border-top","1px solid #B2C8D0");
			}else{
				this.options._pos = "bottom";
				var top = inputOffset.top + this.comboSpan.height() + 2;
				var left = inputOffset.left;		
				this.comboPanel.css({top:top,left:left});
			}		
				
		},
		_selectPrev:function(){
			
			var curItem = this.comboPanel.find(".buss-panel-body-content ul .buss-combo-panel-itemsel:visible");
			if(curItem.length == 0){
				curItem = this.comboPanel.find(".buss-panel-body-content ul li:visible:last");
				curItem.addClass("buss-combo-panel-itemsel");	
			}else if(curItem.prevAll(":visible").length > 0) {
				curItem.prevAll(":visible:first").addClass("buss-combo-panel-itemsel");
				curItem.removeClass("buss-combo-panel-itemsel");
			}
			curItem = this.comboPanel.find(".buss-panel-body ul .buss-combo-panel-itemsel");
			this._changeValue(curItem);

			var panel = this.comboPanel.find(".buss-panel-body-content");
			var top_toolbar = this.comboPanel.find(".buss-panel-body .buss-panel-top-toolbar");
			if(curItem.length > 0 && curItem.position().top - top_toolbar.outerHeight() < 0){
				var h = panel.scrollTop() + curItem.position().top - top_toolbar.outerHeight() ;
				panel.scrollTop(h);
			}		
		},
		_selectNext:function(){			
			var curItem = this.comboPanel.find(".buss-panel-body ul .buss-combo-panel-itemsel");	
			if(curItem.length == 0){
				curItem = this.comboPanel.find(".buss-panel-body ul li:visible:first");
				curItem.addClass("buss-combo-panel-itemsel");	
			}else if(curItem.nextAll(":visible").length > 0){
				curItem.removeClass("buss-combo-panel-itemsel");
				curItem.nextAll(":visible:first").addClass("buss-combo-panel-itemsel");
			}	
			curItem = this.comboPanel.find(".buss-panel-body ul .buss-combo-panel-itemsel");
			this._changeValue(curItem);
			
			var panel = this.comboPanel.find(".buss-panel-body-content");
			var top_toolbar = this.comboPanel.find(".buss-panel-body .buss-panel-top-toolbar");
			var bottom_toolbar = this.comboPanel.find(".buss-panel-body .buss-panel-bottom-toolbar");			
			 if(curItem.length > 0 && curItem.position().top  >= panel.height()){
				var h = panel.scrollTop() + curItem.position().top + curItem.outerHeight() - panel.outerHeight();
				h -= top_toolbar.outerHeight();
				panel.scrollTop(h);
			}			
		},
		getIndexValue:function(index){
			var selItem = this.comboPanel.find(".buss-panel-body-content ul li").eq(index);
			if (selItem.length ==0){
				return null;
			}
			return {value:selItem.attr('val'),text:selItem.text()}			
			
		},
		getValue:function(value){
			var selItem = this.comboPanel.find(".buss-panel-body-content li[val="+value+"]");
			if (selItem.length ==0){
				return null;
			}
			
			return {value:selItem.attr('val'),text:selItem.text()}
		},
		setIndexValue:function(index,text){
			var selItem = this.comboPanel.find(".buss-panel-body-content ul li").eq(index);
			if(selItem.length == 0){
				return false;
			}
			var option = this.element.find("option").eq(index);
			option.html(text);
			selItem.text(text);
			return true; 
		},
		setValue:function(value,text){
			var selItem = this.comboPanel.find(".buss-panel-body-content li[val="+value+"]");
			if(selItem.length == 0){
				return false;
			}
			var option = this.element.find("option[value="+value+"]");
			option.html(text);
			selItem.text(text);
			return true; 
		},
		addItem:function(value,text){
			_self = this;
			var item = $("<li/>").attr("val",value).text(text);
			this.comboPanel.find(".buss-panel-body-content ul").append(item);
			var option = $("<option/>").val(value).html(text);
			this.element.append(option);
			this._bindEvents();
			
			item.click(function(){					
				_self._changeValue($(this));					
				_self.comboPanel.panel("close");
			})
		},
		filter:function(){	
			var panel = this.comboPanel;
			var value = this.comboSpan.find(".buss-combo-text").val();
			var filterItem = panel.find(".buss-panel-body-content ul li:not(:Contains('"+value+"'))");
			panel.find(".buss-panel-body-content ul li").removeClass("buss-combo-panel-itemsel").show();
			filterItem.hide();
			var ulHeight = panel.find("ul").height();
			var panelHeight = panel.panel("option","height");
			var ctxHeight = panelHeight - panel.find(".buss-panel-body .buss-panel-top-toolbar").outerHeight() + panel.find(".buss-panel-body .buss-panel-bottom-toolbar").outerHeight();
			if(ulHeight < ctxHeight){
				panel.panel("setBodyHeight",ulHeight);
				if (this.options._pos == "top"){
					//this.comboPanel.css({top:top,left:left});
					panel.css({top:panel.offset().top + (ctxHeight - ulHeight)});
					//alert(panel.offset().top);
				}
			}else{				
				panel.panel("setBodyHeight",ctxHeight);
				if (this.options._pos == "top"){
					var top = this.comboSpan.offset().top - panel.height() + 3;		
					panel.css({top:top});
				}
			}
		},
		_bindEvents:function(){
			var _self = this;
			$("dobument").unbind(".combo");
			_self.comboPanel.unbind(".combo");
			_self.comboSpan.find(".buss-combo-text").unbind(".combo");
			_self.comboSpan.find(".buss-combo-arrow").unbind(".combo");
			$(document).bind("mousedown.combo",function(e){						
				_self.comboPanel.panel("close");
			})
			_self.comboPanel.bind('mousedown.combo',function(e){
				e.stopPropagation();
				return false;
			})
			
			_self.comboSpan.find(".buss-combo-text").bind("focus.combo",function(e){				
					
				_self.comboPanel.panel("restore");
			}).bind("mousedown.combo",function(e){			
				e.stopPropagation();		
			}).bind('keyup.combo',function(e){
				switch(e.keyCode){
					case $.ui.keyCode.LEFT:
					case $.ui.keyCode.UP:
						if (_self.comboPanel.panel("option",'minimized') == true){
							_self.comboPanel.panel("restore");
							return;
						};
						_self._selectPrev();
						_self.options.selectPrev.call(_self.comboPanel);
						break;
					case $.ui.keyCode.RIGHT:
					case $.ui.keyCode.DOWN:
						if (_self.comboPanel.panel("option",'minimized') == true){
							_self.comboPanel.panel("restore");
							return;
						}
						_self._selectNext();
						_self.options.selectNext.call(_self.comboPanel);
						break;
					case $.ui.keyCode.ENTER:
						var curSelItem = _self.comboPanel.find("ul .combo-panel-itemsel");						
						if(curSelItem.length > 0){
							_self.element.val(curSelItem.attr('val'));
							_self.comboSpan.find(".buss-combo-value").val(curSelItem.attr('val'));							
							_self.comboSpan.find(".buss-combo-text").val(curSelItem.text());	
						}
						_self.comboPanel.panel("close");
						break;
					case $.ui.keyCode.ESCAPE:
						_self.comboPanel.panel("close");
						break;					
					default:
						if(_self.options.filter == true){
							_self.filter();
						}
				}
			}).bind("keydown.combo",function(e){
				switch (e.keyCode) {
					case $.ui.keyCode.TAB:
						_self.comboPanel.panel("close");
						break;
				}
			})
			_self.comboSpan.find(".buss-combo-arrow").bind("click.combo",function(){
				_self.comboSpan.find(".buss-combo-text").focus();
			});
			
		}
	})
})(jQuery);


/**
 * @author gykl 下拉树 需要库包括 
 * jquery-ui.js buss.panel.js buss.combo.js
 *         buss.tree.js 
 */
(function($,undefined){
	$.widget("ui.combotree",{
		options:{
			width:'auto',
			panelWidth:null,
			panelHeight:200,
			valueCol:'id',
			textCol:'name',
			splitSymbol:',',
			editable:false,
			topTools:[],
			bottomTools:[],
			treeSetting:{
				checkable: false,
				showLine: true,
				checkStyle: 'checkbox',
				checkRadioType:"all",
				checkedCol: "checked",
				async: false,
				asyncUrl: "",
				asyncDataCol:"result.data",
				asyncParam: [],
				asyncParamOther: [],
				treeNodeKey: "",
				treeNodeParentKey: "",
				hasChildKey:"hasChild",
				nameCol: "name",
				nodesCol: "nodes",
				checkedCol: "checked", 
				callback: {
					click:null,
					onSelectBefore:null,
					onSelected:null,
					asyncSuccess:null,
					asyncError:null,
					nodeCreated:null
				}
			}
		},
		_create:function(){
			this.comboSpan = $("<span class='buss-combo'/>").insertAfter(this.element);
			this.element.addClass("buss-combo-value").hide().appendTo(this.comboSpan);
			$("<input class='buss-combo-text' type='text'/>").appendTo(this.comboSpan);
			$("<span><span class='buss-combo-arrow'></span></span>").appendTo(this.comboSpan);
			this.comboPanel = $("<div class='buss-combo-panel' style='position:absolute;display:block;'/>");
			var treePanel = $("<ul class='buss-treepanel tree'></ul>");
			this.comboPanel.append(treePanel);
		},
		_init:function(){
			var _self = this;
			var opts = this.options;
			var _width = this.element.outerWidth();
			
			if (!opts.editable){
				this.comboSpan.find(".buss-combo-text").attr("readonly","readonly");
			}
			
			if(opts.width != 'auto'){
				_width = opts.width;
			}
			this.comboSpan.find(".buss-combo-text").css("width",_width - this.comboSpan.find(".buss-combo-arrow").outerWidth());
			var _panelWidth = 0;
			if(opts.panelWidth == null){
				_panelWidth = _width + 2;
			}else{
				_panelWidth = opts.panelWidth + 2;
			}			
			
			this.comboPanel.panel({
				width:_panelWidth,
				height:opts.panelHeight,
				topTools:opts.topTools,
				bottomTools:opts.bottomTools,
				onRestore:function(){
					var zIndex = parseInt(_self.comboPanel.css('z-index'));
					zIndex = isNaN(zIndex) ? 0 : zIndex;
					var maxZIndex = $.maxZIndex();
					if (maxZIndex == 0 || maxZIndex > zIndex){
						_self.comboPanel.css("z-index",maxZIndex + 1);
					}					
					var vals = _self.element.val();
					_self.selectNodes(vals);
					_self._setPosition();
				}
			});
			this.comboPanel.find(".buss-panel-body").addClass("buss-combo-panel-topborder");
			
			
			opts.treeSetting.callback.click = function(event,treeObjId,treeNode){
				
				var textKey = opts.textCol;
				if($.isFunction(opts.treeSetting.callback.onSelectBefore)){					
					if(opts.treeSetting.callback.onSelectBefore.call(_self.comboPanel,treeNode) == false) return;
				}
				
				_self.comboSpan.find(".buss-combo-text").val(treeNode[textKey]);		
				_self.element.val(treeNode[opts.valueCol]);
				_self.comboPanel.panel("close");
				if($.isFunction(opts.treeSetting.callback.onSelected)){
					opts.treeSetting.callback.onSelected.call(_self.comboPanel,treeNode);
				}
			}
			
			this.comboTree = this.comboPanel.find(".buss-treepanel").zTree(opts.treeSetting,opts.treeSetting.treeData);
			
			if(this.updateText()){
				
				this.element.unbind("_destroy.buss");
				this.element.bind("_destroy.buss",function(){
					_self.comboPanel.remove();
				})
				
				this.comboPanel.panel("close");
				this._bindEvents();
			}
		},
		getSelectedNode:function(){
			var node = this.comboTree.getSelectedNode();
			
		},
		_setPosition:function(){
			var inputOffset = this.comboSpan.offset();
			var bottomGap = $(window).height() - inputOffset.top + this.comboSpan.outerHeight();
			
			if(inputOffset.top >= this.comboPanel.outerHeight() && bottomGap <= this.comboPanel.outerHeight()){
				this.options._pos = "top";
				var top = inputOffset.top - this.comboPanel.outerHeight() + 3;
				var left = inputOffset.left;		
				this.comboPanel.css({top:top,left:left});
				this.comboPanel.find(".buss-panel-top-toolbar").css("border-top","1px solid #B2C8D0");
			}else{
				this.options._pos = "bottom";
				var top = inputOffset.top + this.comboSpan.height() + 2;
				var left = inputOffset.left;		
				this.comboPanel.css({top:top,left:left});
			}		
		},
		getValueAndText:function(){
			var text = this.comboSpan.find(".buss-combo-text").val();
			var value = this.element.val();
			return {text:text,value:value};
		},
		selectNodes:function(values,checkTypeFlag){
			if ($.trim(values) == "") return;
			var tmpVals = values.split(this.options.splitSymbol);
			var tmpValsLen = tmpVals.length;
			var key = this.options.valueCol;			
			if (tmpValsLen == 1){				
				var node = this.comboTree.getNodeByParam(key,tmpVals[0]);
				if (!node){
					return;
				}
				this.comboTree.selectNode(node);
			}else{
				for (var i = 0;i < tmpValsLen;i++){
					var node = this.comboTree.getNodeByParam(key,tmpVals[i]);
					if(!node) continue;
					if(this.options.treeSetting.checkable){
						node[this.options.treeSetting.checkedCol] = true;
						this.comboTree.updateNode(node,checkTypeFlag);						
					}else{
						this.comboTree.selectNode(node);
					}
				}
			}
		},
		updateText:function(){
			var text = "";
			var value = this.element.val();
			if($.trim(value) == "") return;
			var tmpVals = value.split(this.options.splitSymbol);
			var tmpValsLen = tmpVals.length;
			var key = this.options.valueCol;
			if(tmpValsLen == 1){
				var node = this.comboTree.getNodeByParam(key,tmpVals[0]);				
				if(!node){
					return;
				}
				this.comboSpan.find(".buss-combo-text").val(node[this.options.textCol]);
			}else{
				this.comboSpan.find(".buss-combo-text").val("");
				for(var i = 0;i < tmpValsLen;i++){
					var node = this.comboTree.getNodeByParam(key,tmpVals[i]);
					if(!node) continue;
					var tmpText = this.comboSpan.find(".buss-combo-text").val();
					if(tmpText == ""){
						this.comboSpan.find(".buss-combo-text").val(node[this.options.textCol]);
					}else{
						this.comboSpan.find(".buss-combo-text").val(tmpText + this.options.splitSymbol + node[this.options.textCol]);
					}
				}
			}
			return true;
		},
		reAsyncChildNodes:function(parentNode,reloadType){
			this.comboTree.reAsyncChildNodes(parentNode,reloadType);
		},
		getTree:function(){
			return this.comboTree;
		},
		_bindEvents:function(){
			var _self = this;
			$("dobument").unbind(".combotree");
			_self.comboPanel.unbind(".combotree");
			_self.comboSpan.find(".buss-combo-text").unbind(".combotree");
			_self.comboSpan.find(".buss-combo-arrow").unbind(".combotree");
			
			$(document).bind("mousedown.combotree",function(e){						
				_self.comboPanel.panel("close");
			})
			
			_self.comboPanel.bind('mousedown.combotree',function(e){
				e.stopPropagation();
				return false;
			})
			
			_self.comboSpan.find(".buss-combo-text").bind("focus.combotree",function(e){				
				_self.comboPanel.panel("restore");
			}).bind("mousedown.combotree",function(e){			
				e.stopPropagation();		
			}).bind('keyup.combo',function(e){
				switch(e.keyCode){
					case $.ui.keyCode.LEFT:
					case $.ui.keyCode.UP:
						if (_self.comboPanel.panel("option",'minimized') == true){
							_self.comboPanel.panel("restore");
							return;
						};
						break;
					case $.ui.keyCode.RIGHT:
					case $.ui.keyCode.DOWN:
						if (_self.comboPanel.panel("option",'minimized') == true){
							_self.comboPanel.panel("restore");
							return;
						}
						break;
					case $.ui.keyCode.ESCAPE:
						_self.comboPanel.panel("close");
						break;					
				}
			})
			
			_self.comboSpan.find(".buss-combo-arrow").bind("click.combotree",function(){
				_self.comboSpan.find(".buss-combo-text").focus();
			});
		}
		
	})
})(jQuery);

//d.ui.mouse
/*
 * jQuery Dialog 0.1
 * http://www.bsweb.com.cn
 * 需要库文件
 * 		jquery-ui.js
 * 		buss.toolbar.js
 * 		buss.panel.js
 * 		buss.button.js
 */
(function($,undefined){
	$.widget("ui.dialog",$.ui.panel,{
		options:{		
			header:true,
			closable:true,			
			modal:true,
			draggable:true,
			opacity:0.5,
			isDialog:true,
			cls:'buss_overlay',
			position:{
				of:'body',
				my:'center',
				at:'center',
				collision:'fit',
				using: function(pos) {					
					var topOffset = $(this).css(pos).offset().top;
					if (topOffset < 0) {
						$(this).css('top', pos.top - topOffset);
					}
				}
			},	
			buttonAlign:"center",
			buttonGap:30,
			buttons:null
		},
		_init:function(){			
			this._initPanel();	
			var _self = this;
			var panelTemplate = this.panelTemplate;	
			var maxZIndex = $.maxZIndex();	
			if(this.options.modal){				 
				this.overlay = $.fn.overlay({
										zIndex:++maxZIndex,
										opacity:this.options.opacity,
										cls:this.options.cls
									});			
				
			}			
			
			if (this.options.buttons != null) {
				this.panelBodyTemplate.append("<div class='buttonPanel'/>")
				var buttonPanelChild = $("<div style='margin-top:3px;'/>");
				this.panelBodyTemplate.find(".buttonPanel").append(buttonPanelChild);
				 if(this.options.buttonAlign == "left"){
					buttonPanelChild.css("margin-left","20px");
				}else if(this.options.buttonAlign == "right"){
					buttonPanelChild.css("margin-right","20px");
				}				
				//buttonPanelChild.css();
				buttonPanelChild.css({'line-height':'30px','text-align':this.options.buttonAlign});
				for(var i = 0 ;i < this.options.buttons.length; i++){
					var btn = $("<a>").button(this.options.buttons[i]);
					if (i > 0) {
						btn.css('margin-left', this.options.buttonGap + "px");
					}
					buttonPanelChild.append(btn);
				}

				var height = this.panelTemplate.height();
				panelTemplate.height(height + this.panelBodyTemplate.find('.buttonPanel').height());
			}
			panelTemplate.css({
				position: 'absolute',
				zIndex:++maxZIndex
			})
			panelTemplate.position(this.options.position);
			if (this.options.draggable == true) {
				panelTemplate.draggable({
					handle: ".buss-panel-header"
				});
			}
			panelTemplate.find(".buss-panel-header").bind("mousedown.dialog",function(e){
				var zIndex = parseInt(panelTemplate.css('z-index'));
				zIndex = isNaN(zIndex) ? 0 : zIndex;
				var maxZIndex = $.maxZIndex();
				if (maxZIndex == 0 || maxZIndex > zIndex){
					panelTemplate.css("z-index",maxZIndex + 1);
				}
			})
		},
		close:function(target){
			this._close(target);
			if(this.options.modal == true){
				this.overlay.minimize();
			}
		},
		destroy:function(target){
			//alert("tt");
			this._destroy(target);
			if(this.options.modal == true){
				this.overlay.destroy();
			}
		},
		minimize:function(target){
			this._minimize();
			if(this.options.modal == true){
				this.overlay.minimize();
			}
		},
		restore:function(target){			
			if(this.options.modal == true){
				this.overlay.restore();
			}
			this._restore(target);
		}
	});
	$.extend({
        alert:function(title,message,width,height,type,fn){
            var imgCls = "infoimg";
            if(type === "warning"){
                imgCls = "warningimg";
            }else if(type === "success"){
                imgCls = "successimg";
            }else if(type === "error"){
                imgCls = "errorimg";
            }else{
                imgCls = "infoimg";
			
            }
            var html = "<div><div class='alert "+imgCls+"'>"+message+"</div></div>";
            var dlg = $(html).dialog({
                title:title,
                width:width,
                height:height,
                iconCls:'icon',
                buttons:[{
                	text:"确 定",
                	type:'button',
                	plain:false,
                	handler:function(){
                		if($.isFunction(fn)){
                            fn();
                        }
                		dlg.dialog("destroy");
                	}
                }]
            });
        },
        confirm:function(title,message,width,height,fn1,fn2){
            var html = "<div><div class='alert infoimg'>"+message+"</div></div>";
            var dlg = $(html).dialog({
                title:title,
                width:width,
                height:height,
                iconCls:'icon',
                buttons:[
                     {text:'确 定',type:'button',plain:false,handler:function(){
	                    	 if($.isFunction(fn1)){
	                             fn1();
	                         }
	                         dlg.dialog("destroy");
                     }},
                     {text:'取 消',type:'button',plain:false,handler:function(){
                    	 if($.isFunction(fn2)){
                             fn2();
                         }
                         dlg.dialog("destroy");
                     }}
                ]
         })
        }
	})
	
})(jQuery);



/*
 * JQuery zTree 2.4
 * http://code.google.com/p/jquerytree/
 *
 * Copyright (c) 2010 Hunter.z
 *
 * Date: 2011-02-10
 *
 */

(function($) {

	var ZTREE_NODECREATED = "ZTREE_NODECREATED";
	var ZTREE_CLICK = "ZTREE_CLICK";
	var ZTREE_RIGHTCLICK = "ZTREE_RIGHTCLICK";
	var ZTREE_CHANGE = "ZTREE_CHANGE";
	var ZTREE_RENAME = "ZTREE_RENAME";
	var ZTREE_REMOVE = "ZTREE_REMOVE";
	var ZTREE_DRAG = "ZTREE_DRAG";
	var ZTREE_DROP = "ZTREE_DROP";
	var ZTREE_EXPAND = "ZTREE_EXPAND";
	var ZTREE_COLLAPSE = "ZTREE_COLLAPSE";
	var ZTREE_ASYNC_SUCCESS = "ZTREE_ASYNC_SUCCESS";
	var ZTREE_ASYNC_ERROR = "ZTREE_ASYNC_ERROR";

	var IDMark_Switch = "_switch";
	var IDMark_Icon = "_ico";
	var IDMark_Span = "_span";
	var IDMark_Input = "_input";
	var IDMark_Check = "_check";
	var IDMark_Edit = "_edit";
	var IDMark_Remove = "_remove";
	var IDMark_Ul = "_ul";
	var IDMark_A = "_a";

	var LineMark_Root = "root";
	var LineMark_Roots = "roots";
	var LineMark_Center = "center";
	var LineMark_Bottom = "bottom";
	var LineMark_NoLine = "noLine";
	var LineMark_Line = "line";

	var FolderMark_Open = "open";
	var FolderMark_Close = "close";
	var FolderMark_Docu = "docu";

	var Class_CurSelectedNode = "curSelectedNode";
	var Class_CurSelectedNode_Edit = "curSelectedNode_Edit";
	var Class_TmpTargetTree = "tmpTargetTree";
	var Class_TmpTargetNode = "tmpTargetNode";
	
	var Check_Style_Box = "checkbox";
	var Check_Style_Radio = "radio";
	var CheckBox_Default = "chk";
	var CheckBox_False = "false";
	var CheckBox_True = "true";
	var CheckBox_Full = "full";
	var CheckBox_Part = "part";
	var CheckBox_Focus = "focus";
	var Radio_Type_All = "all";
	var Radio_Type_Level = "level";
	
	var MoveType_Inner = "inner";
	var MoveType_Before = "before";
	var MoveType_After = "after";
	var MinMoveSize = "5";

	var settings = new Array();
	var zTreeId = 0;

	//zTree构造函数
	$.fn.zTree = function(zTreeSetting, zTreeNodes) {
		
		var setting = {
			//Tree 唯一标识，主UL的ID
			treeObjId: "",
			//是否显示CheckBox
			checkable: false,
			//是否在编辑状态
			editable: false,
			//编辑状态是否显示修改按钮
			edit_renameBtn:true,
			//编辑状态是否显示删除节点按钮
			edit_removeBtn:true,
			//是否显示树的线
			showLine: true,
			//当前被选择的TreeNode
			curTreeNode: null,
			//当前正被编辑的TreeNode
			curEditTreeNode: null,
			//是否处于拖拽期间 0: not Drag; 1: doing Drag
			dragStatus: 0,
			dragNodeShowBefore: false,
			//选择CheckBox 或 Radio
			checkStyle: Check_Style_Box,
			//checkBox点击后影响父子节点设置（checkStyle=Check_Style_Radio时无效） 			
			checkType: {
				"Y": "ps",
				"N": "ps"
			},
			//radio 最大个数限制类型，每一级节点限制 或 整棵Tree的全部节点限制（checkStyle=Check_Style_Box时无效）
			checkRadioType:Radio_Type_Level,
			//checkRadioType = Radio_Type_All 时，保存被选择节点的堆栈
			checkRadioCheckedList:[],
			//是否异步获取节点数据
			async: false,
			//获取节点数据的URL地址
			asyncUrl: "",
			//获取数据的熟悉名(new)
			asyncDataCol:"result.data",
			//获取节点数据时，必须的数据名称，例如：id、name
			asyncParam: [],
			//其它参数
			asyncParamOther: [],
			//简单Array数组转换为JSON嵌套数据参数
			isSimpleData: false,
			treeNodeKey: "",
			treeNodeParentKey: "",
			hasChildKey:"hasChild",
			//用户自定义名称列
			nameCol: "name",
			//用户自定义子节点列
			nodesCol: "nodes", 
			//用户自定义checked列
			checkedCol: "checked", 
			//折叠、展开特效速度
			expandSpeed: "fast",
			//折叠、展开Trigger开关
			expandTriggerFlag:false,
			//hover 增加按钮接口
			addHoverDom:null,
			//hover 删除按钮接口
			removeHoverDom:null,
			//永久自定义显示控件方法
			addDiyDom:null,
			//字体个性化样式接口
			fontCss:{},
			
			root: {
				isRoot: true,
				nodes: []
			},
			//event Function
			callback: {
				beforeClick:null,
				beforeRightClick:null,
				beforeMouseDown:null,
				beforeMouseUp:null,
				beforeChange:null,
				beforeDrag:null,
				beforeDrop:null,
				beforeRename:null,
				beforeRemove:null,
				beforeExpand:null,
				beforeCollapse:null,		
				beforeAsyncSuccess:null,
				nodeCreated:null,
				click:null,
				rightClick:null,
				mouseDown:null,
				mouseUp:null,
				change:null,
				drag:null,
				drop:null,
				rename:null,
				remove:null,
				expand:null,
				collapse:null,
				asyncSuccess:null,
				asyncError:null
			}			
		};

		if (zTreeSetting) {
			var tmp_checkType = zTreeSetting.checkType;
			zTreeSetting.checkType = undefined;
			var tmp_callback = zTreeSetting.callback;
			zTreeSetting.callback = undefined;
			var tmp_root = zTreeSetting.root;
			zTreeSetting.root = undefined;
			
			$.extend(setting, zTreeSetting);
			
			zTreeSetting.checkType = tmp_checkType;				
			$.extend(true, setting.checkType, tmp_checkType);
			zTreeSetting.callback = tmp_callback;				
			$.extend(setting.callback, tmp_callback);
			zTreeSetting.root = tmp_root;				
			$.extend(setting.root, tmp_root);
		}

		setting.treeObjId = this.attr("id");
		setting.treeObj = this;
		setting.root.tId = -1;
		setting.root.name = "ZTREE ROOT";
		setting.root.isRoot = true;
		setting.checkRadioCheckedList = [];
		setting.curTreeNode = null;
		setting.curEditTreeNode = null;
		setting.dragNodeShowBefore = false;
		setting.dragStatus = 0;
		setting.expandTriggerFlag = false;
		if (!setting.root[setting.nodesCol]) setting.root[setting.nodesCol]= [];
		zTreeId = 0;

		if (zTreeNodes) {
			setting.root[setting.nodesCol] = zTreeNodes;
		}
		if (setting.isSimpleData) {
			setting.root[setting.nodesCol] = transformTozTreeFormat(setting, setting.root[setting.nodesCol]);
		}
		settings[setting.treeObjId] = setting;

		setting.treeObj.empty();

		bindTreeNodes(setting, this);
		
		if (setting.root[setting.nodesCol] && setting.root[setting.nodesCol].length > 0) {
			
			initTreeNodes(setting, 0, setting.root[setting.nodesCol]);
		} else if (setting.async && setting.asyncUrl && setting.asyncUrl.length > 0) {
			
			asyncGetNode(setting);
		}
		
		return new zTreePlugin().init(this);

	};

	//绑定事件
	function bindTreeNodes(setting, treeObj) {
		treeObj.unbind(ZTREE_NODECREATED);		
		treeObj.bind(ZTREE_NODECREATED, function (event, treeId, treeNode) {
			if ((typeof setting.callback.nodeCreated) == "function") setting.callback.nodeCreated(event, treeId, treeNode);
		});

		treeObj.unbind(ZTREE_CLICK);		
		treeObj.bind(ZTREE_CLICK, function (event, treeId, treeNode) {
		  if ((typeof setting.callback.click) == "function") setting.callback.click(event, treeId, treeNode);
		});
		
		treeObj.unbind(ZTREE_CHANGE);
		treeObj.bind(ZTREE_CHANGE, function (event, treeId, treeNode) {
		  if ((typeof setting.callback.change) == "function") setting.callback.change(event, treeId, treeNode);
		});

		treeObj.unbind(ZTREE_RENAME);
		treeObj.bind(ZTREE_RENAME, function (event, treeId, treeNode) {
			if ((typeof setting.callback.rename) == "function") setting.callback.rename(event, treeId, treeNode);
		});
		
		treeObj.unbind(ZTREE_REMOVE);
		treeObj.bind(ZTREE_REMOVE, function (event, treeId, treeNode) {
			if ((typeof setting.callback.remove) == "function") setting.callback.remove(event, treeId, treeNode);
		});

		treeObj.unbind(ZTREE_DRAG);
		treeObj.bind(ZTREE_DRAG, function (event, treeId, treeNode) {
		  if ((typeof setting.callback.drag) == "function") setting.callback.drag(event, treeId, treeNode);
		});

		treeObj.unbind(ZTREE_DROP);
		treeObj.bind(ZTREE_DROP, function (event, treeId, treeNode, targetNode, moveType) {
		  if ((typeof setting.callback.drop) == "function") setting.callback.drop(event, treeId, treeNode, targetNode, moveType);
		});

		treeObj.unbind(ZTREE_EXPAND);
		treeObj.bind(ZTREE_EXPAND, function (event, treeId, treeNode) {
			if ((typeof setting.callback.expand) == "function") setting.callback.expand(event, treeId, treeNode);
		});

		treeObj.unbind(ZTREE_COLLAPSE);
		treeObj.bind(ZTREE_COLLAPSE, function (event, treeId, treeNode) {
			if ((typeof setting.callback.collapse) == "function") setting.callback.collapse(event, treeId, treeNode);
		});

		treeObj.unbind(ZTREE_ASYNC_SUCCESS);
		treeObj.bind(ZTREE_ASYNC_SUCCESS, function (event, treeId, treeNode, msg) {
		  if ((typeof setting.callback.asyncSuccess) == "function") setting.callback.asyncSuccess(event, treeId, treeNode, msg);
		});

		treeObj.unbind(ZTREE_ASYNC_ERROR);
		treeObj.bind(ZTREE_ASYNC_ERROR, function (event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
		  if ((typeof setting.callback.asyncError) == "function") setting.callback.asyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown);
		});
		
		setting.treeObj.bind('contextmenu',
			function(event) {
				var targetObj = $(event.target);
				var treeNode = getTreeNodeByDom(setting, targetObj);
				var doRight = true;
				if ((typeof setting.callback.beforeRightClick) == "function") {
					doRight = setting.callback.beforeRightClick(setting.treeObjId, treeNode);
				}
				//触发rightClick事件
				if (doRight && (typeof setting.callback.rightClick) == "function") {
					setting.callback.rightClick(event, setting.treeObjId, treeNode);
					return false;
				} 
				return (typeof setting.callback.rightClick) != "function";
			});
		
		setting.treeObj.bind('mouseup',
			function(event) {
				var targetObj = $(event.target);
				var treeNode = getTreeNodeByDom(setting, targetObj);
				var doMouseUp = true;
				if ((typeof setting.callback.beforeMouseUp) == "function") {
					doMouseUp = setting.callback.beforeMouseUp(setting.treeObjId, treeNode);
				}
				//触发mouseUp事件
				if (doMouseUp && (typeof setting.callback.mouseUp) == "function") {
					setting.callback.mouseUp(event, setting.treeObjId, treeNode);
				}
				return true;
			});
		setting.treeObj.bind('mousedown',
			function(event) {
				var targetObj = $(event.target);
				var treeNode = getTreeNodeByDom(setting, targetObj);
				var doMouseDown = true;
				if ((typeof setting.callback.beforeMouseDown) == "function") {
					doMouseDown = setting.callback.beforeMouseDown(setting.treeObjId, treeNode);
				}
				//触发mouseDown事件
				if (doMouseDown && (typeof setting.callback.mouseDown) == "function") {
					setting.callback.mouseDown(event, setting.treeObjId, treeNode);
				}
				return true;
			});
	}
	
	//根据Dom获取treeNode数据
	function getTreeNodeByDom(setting, obj) {
		var treeNode;
		var targetObj = $(obj);
		if (targetObj.attr("id") == setting.treeObjId) {
			treeNode = null;
		} else {
			while (!targetObj.is("li") && targetObj.attr("id") != setting.treeObjId) {
				targetObj = targetObj.parent();
			};
			var tId = targetObj.attr("id");
			treeNode = getTreeNodeByTId(setting, tId);
		}
		return treeNode;
	}

	//初始化并显示节点Json对象
	function initTreeNodes(setting, level, treeNodes, parentNode) {
		if (!treeNodes) return;

		for (var i = 0; i < treeNodes.length; i++) {
			var node = treeNodes[i];
			node.level = level;
			node.tId = setting.treeObjId + "_" + (++zTreeId);
			node.parentNode = parentNode;
			node[setting.checkedCol] = (node[setting.checkedCol] == true);
			node.checkedOld = node[setting.checkedCol];
			node.check_Focus = false;
			node.check_True_Full = true;
			node.check_False_Full = true;
			node.editNameStatus = false;

			var tmpParentNode = (parentNode) ? parentNode: setting.root;

			//允许在非空节点上增加节点
			node.isFirstNode = (tmpParentNode[setting.nodesCol].length == treeNodes.length) && (i == 0);
			node.isLastNode = (i == (treeNodes.length - 1));
			if (node[setting.nodesCol] && node[setting.nodesCol].length > 0) {	
				
				node.open = (node.open) ? true: false;
				node.isParent = true;
				showTree(setting, node);
				if(node.open == true && setting.async == true && !(node[setting.nodesCol] && node[setting.nodesCol].length < 1)){					
					asyncGetNode(setting,node);
				}
				initTreeNodes(setting, level + 1, node[setting.nodesCol], node);

			} else {
				node.open = (node.open) ? true: false;
				node.isParent = (node[setting.hasChildKey]) ? true: false;
				showTree(setting, node);
				if(node.open == true && setting.async == true && !(node[setting.nodesCol] && node[setting.nodesCol].length < 1)){					
					asyncGetNode(setting,node);
				}
				//只在末级节点的最后一个进行checkBox修正
				if (setting.checkable && i == treeNodes.length - 1) {
					repairParentChkClass(setting, node);
				}
			}
		}
	}

	//显示单个节点
	function showTree(setting, treeNode) {

		//获取父节点
		var p = treeNode.parentNode;
		if (!p) {
			p = setting.treeObj;
		} else {
			p = $("#" + treeNode.parentNode.tId + IDMark_Ul);
		}

		var html = "<li id='" + treeNode.tId + "' class='tree-node'>" + "<button type=\"button\" id='" + treeNode.tId + IDMark_Switch + "' title='' onfocus='this.blur();'></button>" + "<a id='" + treeNode.tId + IDMark_A + "' onclick=\"" + (treeNode.click || '') + "\" ><button type=\"button\" id='" + treeNode.tId + IDMark_Icon + "' title='' onfocus='this.blur();'></button><span id='" + treeNode.tId + IDMark_Span + "'></span></a>" + "<ul id='" + treeNode.tId + IDMark_Ul + "'></ul>" + "</li>";
		p.append(html);
		
		var switchObj = $("#" + treeNode.tId + IDMark_Switch);
		var aObj = $("#" + treeNode.tId + IDMark_A);
		var nObj = $("#" + treeNode.tId + IDMark_Span);
		var ulObj = $("#" + treeNode.tId + IDMark_Ul);
		var icoObj = $("#" + treeNode.tId + IDMark_Icon);
		
		setNodeName(setting, treeNode);
		setNodeLineIcos(setting, treeNode);
		setNodeFontCss(setting, treeNode);
		
		//增加树节点展开、关闭事件
		ulObj.css({
			"display": (treeNode.open ? "block": "none")
		});
		if (treeNode.isParent) {
			switchObj.bind('click', {
				treeObjId: setting.treeObjId,
				treeNode: treeNode
			},
			onSwitchNode);
			aObj.bind('dblclick', {
				treeObjId: setting.treeObjId,
				treeNode: treeNode
			},
			onSwitchNode);
		}
		aObj.bind('click',
		function() {
			var beforeClick = true;
			if ((typeof setting.callback.beforeClick) == "function") beforeClick = setting.callback.beforeClick(setting.treeObjId, treeNode);
			if (beforeClick == false) return;
			//除掉默认事件，防止文本被选择
			window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
			//设置节点为选中状态
			selectNode(setting, treeNode);
			//触发click事件
			setting.treeObj.trigger(ZTREE_CLICK, [setting.treeObjId, treeNode]);
		});
		icoObj.bind('mousedown',
		function() {
			treeNode.editNameStatus = false;
		});

		//显示CheckBox Or Radio
		if (setting.checkable) {
			switchObj.after("<BUTTON type='BUTTON' ID='" + treeNode.tId + IDMark_Check + "' onfocus='this.blur();' ></BUTTON>");
			
			var checkObj = $("#" + treeNode.tId + IDMark_Check);
			
			if (setting.checkStyle == Check_Style_Radio && setting.checkRadioType == Radio_Type_All && treeNode[setting.checkedCol] ) {
				setting.checkRadioCheckedList = setting.checkRadioCheckedList.concat([treeNode]);
			}
			
			setChkClass(setting, checkObj, treeNode);
			
			checkObj.bind('click',
			function() {
				var beforeChange = true;
				if ((typeof setting.callback.beforeChange) == "function") beforeChange = setting.callback.beforeChange(setting.treeObjId, treeNode);
				if (beforeChange == false) return;
				
				treeNode[setting.checkedCol] = !treeNode[setting.checkedCol];
				checkNodeRelation(setting, treeNode);
				
				setChkClass(setting, checkObj, treeNode);
				repairParentChkClassWithSelf(setting, treeNode);

				//触发 CheckBox 点击事件
				setting.treeObj.trigger(ZTREE_CHANGE, [setting.treeObjId, treeNode]);

			});
			
			checkObj.bind('mouseover',
			function() {
				treeNode.checkboxFocus = true;
				setChkClass(setting, checkObj, treeNode);
			});

			checkObj.bind('mouseout',
			function() {
				treeNode.checkboxFocus = false;
				setChkClass(setting, checkObj, treeNode);
			});
		}
		
		setNodeTarget(treeNode);
		setNodeUrl(setting, treeNode);
		
		//编辑、删除按钮
		aObj.hover(
			function() {
				addTreeDom(setting, treeNode);
			},
			function() {
				if (setting.curTreeNode != treeNode)
					removeTreeDom(setting, treeNode);
			}
		);

		aObj.bind('mousedown',
		function(eventMouseDown) {

			//右键不能拖拽
			if (eventMouseDown.button == 2 || !setting.editable) return;

			var doc = document;
			var curNode;
			var tmpArrow;
			var tmpTarget;
			var isOtherTree = false;
			var targetSetting = setting;
			var preTmpTargetNodeId = null;
			var preTmpMoveType = null;
			var tmpTargetNodeId = null;
			var moveType = MoveType_Inner;
			var mouseDownX = eventMouseDown.clientX;
			var mouseDownY = eventMouseDown.clientY;
			var startTime = (new Date()).getTime();

			$(doc).mousemove(function(event) {
				
				//为便于输入框正常操作，在输入框内移动鼠标不能拖拽节点
				if (treeNode.editNameStatus) {
					return true;
				}

				//除掉默认事件，防止文本被选择
				window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
				
				//避免鼠标误操作，对于第一次移动小于MinMoveSize时，不开启拖拽功能
				if (setting.dragStatus == 0 && Math.abs(mouseDownX - event.clientX) < MinMoveSize
						 && Math.abs(mouseDownY - event.clientY) < MinMoveSize) {
					return true;
				}

				$("body").css("cursor", "pointer");
				var switchObj = $("#" + treeNode.tId + IDMark_Switch);

				if (setting.dragStatus == 0 && treeNode.isParent && treeNode.open) {
					expandAndCollapseNode(setting, treeNode, !treeNode.open);
					setting.dragNodeShowBefore = true;
				}

				if (setting.dragStatus == 0) {
					//避免beforeDrag alert时，得到返回值之前仍能拖拽的Bug
					setting.dragStatus = -1;
					var beforeDrag = true;
					if ((typeof setting.callback.beforeDrag) == "function") beforeDrag = setting.callback.beforeDrag(setting.treeObjId, treeNode);
					if (beforeDrag == false) return;
					
					setting.dragStatus = 1;
					showIfameMask(true);

					//设置节点为选中状态
					selectNode(setting, treeNode);
					removeTreeDom(setting, treeNode);

					var tmpNode = $("#" + treeNode.tId).clone();
					tmpNode.attr("id", treeNode.tId + "_tmp");
					tmpNode.css("padding", "0");
					tmpNode.children("#" + treeNode.tId + IDMark_A).removeClass(Class_CurSelectedNode);
					tmpNode.children("#" + treeNode.tId + IDMark_Ul).css("display", "none");

					curNode = $("<ul class='zTreeDragUL'></ul>").append(tmpNode);
					curNode.attr("id", treeNode.tId + IDMark_Ul + "_tmp");
					curNode.addClass(setting.treeObj.attr("class"));
					curNode.appendTo("body");

					tmpArrow = $("<button class='tmpzTreeMove_arrow'></button>");
					tmpArrow.attr("id", "zTreeMove_arrow_tmp");
					tmpArrow.appendTo("body");

					//触发 DRAG 拖拽事件，返回正在拖拽的源数据对象
					setting.treeObj.trigger(ZTREE_DRAG, [setting.treeObjId, treeNode]);
				}
				
				if (setting.dragStatus == 1 && tmpArrow.attr("id") != event.target.id) {
					if (tmpTarget) {
						tmpTarget.removeClass(Class_TmpTargetTree);
						if (tmpTargetNodeId) $("#" + tmpTargetNodeId + IDMark_A, tmpTarget).removeClass(Class_TmpTargetNode);
					}
					tmpTarget = null;
					tmpTargetNodeId = null;					
					
					//判断是否不同的树
					isOtherTree = false;
					targetSetting = setting;
					for (var s in settings) {
						if (settings[s].editable && settings[s].treeObjId != setting.treeObjId 
								&& (event.target.id == settings[s].treeObjId || $(event.target).parents("#" + settings[s].treeObjId).length>0)) {
							isOtherTree = true;
							targetSetting = settings[s];
						}
					}

					var docScrollTop = $(doc).scrollTop();
					var docScrollLeft = $(doc).scrollLeft();
					var treeOffset = targetSetting.treeObj.offset();
					var scrollHeight = targetSetting.treeObj.get(0).scrollHeight;
					var scrollWidth = targetSetting.treeObj.get(0).scrollWidth;
					var dTop = (event.clientY + docScrollTop - treeOffset.top);
					var dBottom = (targetSetting.treeObj.height() + treeOffset.top - event.clientY - docScrollTop);
					var dLeft = (event.clientX + docScrollLeft - treeOffset.left);
					var dRight = (targetSetting.treeObj.width() + treeOffset.left - event.clientX - docScrollLeft);
					var isTop = (dTop < 10 && dTop > -5);
					var isBottom = (dBottom < 10 && dBottom > -5);
					var isLeft = (dLeft < 10 && dLeft > -5);
					var isRight = (dRight < 10 && dRight > -5);
					var isTreeTop = (isTop && targetSetting.treeObj.scrollTop() <= 0);
					var isTreeBottom = (isBottom && (targetSetting.treeObj.scrollTop() + targetSetting.treeObj.height()+10) >= scrollHeight);
					var isTreeLeft = (isLeft && targetSetting.treeObj.scrollLeft() <= 0);
					var isTreeRight = (isRight && (targetSetting.treeObj.scrollLeft() + targetSetting.treeObj.width()+10) >= scrollWidth);

					if (event.target.id && targetSetting.treeObj.find("#" + event.target.id).length > 0) {
						//任意节点 移到 其他节点
						var targetObj = $("#" + event.target.id);
						while (!targetObj.is("li") && targetObj.attr("id") != targetSetting.treeObjId) {
							targetObj = targetObj.parent();
						};

						var canMove = false;
						//如果移到自己 或者自己的子集，则不能当做临时目标
						if (treeNode.parentNode && targetObj.attr("id") != treeNode.tId && $("#" + treeNode.tId).find("#" + targetObj.attr("id")).length == 0) {
							//非根节点移动
							canMove = true;
						} else if (treeNode.parentNode == null && targetObj.attr("id") != treeNode.tId && $("#" + treeNode.tId).find("#" + targetObj.attr("id")).length == 0) {
							//根节点移动
							canMove = true;
						}
						if (canMove) {
							if (event.target.id && 
								(event.target.id == (targetObj.attr('id') + IDMark_A) || $(event.target).parents("#" + targetObj.attr('id') + IDMark_A).length > 0)) {
								tmpTarget = targetObj;
								tmpTargetNodeId = targetObj.attr('id');
								$("#" + tmpTargetNodeId + IDMark_A, tmpTarget).addClass(Class_TmpTargetNode);
							}
						}
					}
					
					//确保鼠标在zTree内部
					if (event.target.id == targetSetting.treeObjId || $(event.target).parents("#" + targetSetting.treeObjId).length>0) {
						//只有移动到zTree容器的边缘才算移到 根（排除根节点在本棵树内的移动）
						if (!tmpTarget && (isTreeTop || isTreeBottom || isTreeLeft || isTreeRight) && (isOtherTree || (!isOtherTree && treeNode.parentNode != null))) {
							tmpTarget = targetSetting.treeObj;
							tmpTarget.addClass(Class_TmpTargetTree);
						}
						//滚动条自动滚动
						if (isTop) {
							targetSetting.treeObj.scrollTop(targetSetting.treeObj.scrollTop()-10);
						} else if (isBottom)  {
							targetSetting.treeObj.scrollTop(targetSetting.treeObj.scrollTop()+10);
						}
						if (isLeft) {
							targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft()-10);
						} else if (isRight) {
							targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft()+10);
						}
						//目标节点在可视区域左侧，自动移动横向滚动条
						if (tmpTarget && tmpTarget != targetSetting.treeObj && tmpTarget.offset().left < targetSetting.treeObj.offset().left) {
							targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft()+ tmpTarget.offset().left - targetSetting.treeObj.offset().left);
						}
					}
					
					curNode.css({
						"top": (event.clientY + docScrollTop + 3) + "px",
						"left": (event.clientX + docScrollLeft + 3) + "px"
					});
					
					var dX = 0;
					var dY = 0;
					if (tmpTarget && tmpTarget.attr("id")!=targetSetting.treeObjId) {
						var isPrev = ($("#" + treeNode.tId).prev().attr("id") == tmpTarget.attr("id")) ;
						var isNext = ($("#" + treeNode.tId).next().attr("id") == tmpTarget.attr("id")) ;
						var tmpTargetA = $("#" + tmpTargetNodeId + IDMark_A, tmpTarget);
						var dY_percent = (event.clientY + docScrollTop - tmpTargetA.offset().top)/tmpTargetA.height();
						if (dY_percent<0.25 && dY_percent>=-.2 && !isNext) {
							dX = 1 - tmpArrow.width();
							dY = 0 - tmpArrow.height()/2;
							moveType = MoveType_Before;
						} else if (dY_percent>0.75 && dY_percent<=1.2 && !isPrev) {
							dX = 1 - tmpArrow.width();
							dY = tmpTargetA.height() - tmpArrow.height()/2;
							moveType = MoveType_After;
						} else {
							dX = 5 - tmpArrow.width();
							dY = 0;
							moveType = MoveType_Inner;
						}
						tmpArrow.css({
							"display":"block",
							"top": (tmpTargetA.offset().top + dY) + "px",
							"left": (tmpTargetA.offset().left + dX) + "px"
						});
						
						if (preTmpTargetNodeId != tmpTargetNodeId || preTmpMoveType != moveType) {
							startTime = (new Date()).getTime();
						}
						if (moveType == MoveType_Inner) {
							window.moveTimer = setTimeout(function() {
								if (moveType != MoveType_Inner) return;
								var targetNode = getTreeNodeByTId(targetSetting, tmpTargetNodeId);
								if (targetNode && targetNode.isParent && !targetNode.open && (new Date()).getTime() - startTime > 500) {
									switchNode(targetSetting, targetNode);
								}
							}, 600);
						}
					} else {
						moveType = MoveType_Inner;
						tmpArrow.css({"display":"none"});
						if (window.moveTimer) {clearTimeout(window.moveTimer);}
					}
					preTmpTargetNodeId = tmpTargetNodeId;
					preTmpMoveType = moveType;
				}
				return false;
			});

			$(doc).mouseup(function(event) {
				if (this.moveTimer) {clearTimeout(this.moveTimer);}
				preTmpTargetNodeId = null;
				preTmpMoveType = null;
				$(doc).unbind("mousemove");
				$(doc).unbind("mouseup");
				$("body").css("cursor", "auto");
				if (tmpTarget) {
					tmpTarget.removeClass(Class_TmpTargetTree);
					if (tmpTargetNodeId) $("#" + tmpTargetNodeId + IDMark_A, tmpTarget).removeClass(Class_TmpTargetNode);
				}
				showIfameMask(false);

				if (setting.dragStatus == 0) return;
				setting.dragStatus = 0;

				if (treeNode.isParent && setting.dragNodeShowBefore && !treeNode.open) {
					expandAndCollapseNode(setting, treeNode, !treeNode.open);
					setting.dragNodeShowBefore = false;
				}

				if (curNode) curNode.remove();
				if (tmpArrow) tmpArrow.remove();

				//显示树上 移动后的节点
				if (tmpTarget && tmpTargetNodeId && treeNode.parentNode && tmpTargetNodeId==treeNode.parentNode.tId && moveType == MoveType_Inner) {
					tmpTarget = null;
				}
				if (tmpTarget) {
					var dragTargetNode = tmpTargetNodeId == null ? null: getTreeNodeByTId(targetSetting, tmpTargetNodeId);
					var beforeDrop = true;
					if ((typeof targetSetting.callback.beforeDrop) == "function") beforeDrop = targetSetting.callback.beforeDrop(targetSetting.treeObjId, treeNode, dragTargetNode, moveType);
					if (beforeDrop == false) return;
					
					if (isOtherTree) {
						removeTreeNode(setting, treeNode);
						addTreeNodes(targetSetting, null, [treeNode], false);
						moveTreeNode(targetSetting, dragTargetNode, treeNode, moveType);
						selectNode(targetSetting, treeNode);
					} else {
						moveTreeNode(targetSetting, dragTargetNode, treeNode, moveType);
					}
					$("#" + treeNode.tId + IDMark_Icon).focus().blur();
					
					//触发 DROP 拖拽事件，返回拖拽的目标数据对象
					setting.treeObj.trigger(ZTREE_DROP, [targetSetting.treeObjId, treeNode, dragTargetNode, moveType]);

				} else {
					//触发 DROP 拖拽事件，返回null
					setting.treeObj.trigger(ZTREE_DROP, [setting.treeObjId, null, null, null]);
				}
			});
			
			//阻止默认事件专门用于处理 FireFox 的Bug，
			//该 Bug 导致如果 zTree Div CSS 中存在 overflow 设置，则拖拽节点移出 zTree 时，无法得到正确的event.target
			if(eventMouseDown.preventDefault) {
				eventMouseDown.preventDefault();
		    }
		});
		
		if ((typeof setting.addDiyDom) == "function") {
			setting.addDiyDom(setting.treeObjId, treeNode);
		}
		//触发nodeCreated事件
		setting.treeObj.trigger(ZTREE_NODECREATED, [setting.treeObjId, treeNode]);
	}

	//获取对象的绝对坐标
	function getAbsPoint(obj) {
		var r = new Array(2);
		oRect = obj.getBoundingClientRect();
		r[0] = oRect.left;
		r[1] = oRect.top;
		return r;
	}
	
	//设置光标位置函数
	function setCursorPosition(obj, pos){
		if(obj.setSelectionRange) {
			obj.focus();
			obj.setSelectionRange(pos,pos);
		} else if (obj.createTextRange) {
			var range = obj.createTextRange();
			range.collapse(true);
			range.moveEnd('character', pos);
			range.moveStart('character', pos);
			range.select();
		}
	}

	var dragMaskList = new Array();
	//显示、隐藏 Iframe的遮罩层（主要用于避免拖拽不流畅）
	function showIfameMask(showSign) {
		//清空所有遮罩
		while (dragMaskList.length > 0) {
			dragMaskList[0].remove();
			dragMaskList.shift();
		}
		if (showSign) {
			//显示遮罩
			var iframeList = $("iframe");
			for (var i = 0; i < iframeList.length; i++) {
				var obj = iframeList.get(i);
				var r = getAbsPoint(obj);
				var dragMask = $("<div id='zTreeMask_" + i + "' class='zTreeMask' style='top:" + r[1] + "px; left:" + r[0] + "px; width:" + obj.offsetWidth + "px; height:" + obj.offsetHeight + "px;'></div>");
				dragMask.appendTo("body");
				dragMaskList.push(dragMask);
			}
		}
	}
	
	//设置Name
	function setNodeName(setting, treeNode) {
		var nObj = $("#" + treeNode.tId + IDMark_Span);
		nObj.text(treeNode[setting.nameCol]);
	}
	//设置Target
	function setNodeTarget(treeNode) {
		var aObj = $("#" + treeNode.tId + IDMark_A);
		aObj.attr("target", (treeNode.target || "_blank"));
	}
	//设置URL
	function setNodeUrl(setting, treeNode) {
		var aObj = $("#" + treeNode.tId + IDMark_A);
		if (treeNode.url && !setting.editable) aObj.attr("href", treeNode.url);
		else aObj.removeAttr("href");
	}
	//设置Line、Ico等css属性
	function setNodeLineIcos(setting, treeNode) {
		if (!treeNode) return;
		var switchObj = $("#" + treeNode.tId + IDMark_Switch);
		var aObj = $("#" + treeNode.tId + IDMark_A);
		var ulObj = $("#" + treeNode.tId + IDMark_Ul);
		var icoObj = $("#" + treeNode.tId + IDMark_Icon);
		
		switchObj.attr("class", "switch");
		if (setting.showLine) {
			if (treeNode.level == 0 && treeNode.isFirstNode && treeNode.isLastNode) {
				switchObj.attr("class", "switch_" + LineMark_Root);
			} else if (treeNode.level == 0 && treeNode.isFirstNode) {
				switchObj.attr("class", "switch_" + LineMark_Roots);
			} else if (treeNode.isLastNode) {
				switchObj.attr("class", "switch_" + LineMark_Bottom);
			} else {
				switchObj.attr("class", "switch_" + LineMark_Center);
			}
			if (treeNode.isLastNode) {
				ulObj.removeClass(LineMark_Line);
			} else {
				ulObj.addClass(LineMark_Line);
			}
		} else {
			switchObj.attr("class", "switch_" + LineMark_NoLine);
		}

		icoObj.attr("class", (treeNode.iconSkin ? treeNode.iconSkin : ""));
		if (treeNode.isParent) {
			var tmpOpen = (treeNode.open ? ("_" + FolderMark_Open) : ("_" + FolderMark_Close));
			switchObj.attr("class", switchObj.attr("class") + tmpOpen);
			icoObj.addClass("ico" + tmpOpen);
		} else {
			switchObj.attr("class", switchObj.attr("class") + "_" + FolderMark_Docu);
			icoObj.addClass("ico_" + FolderMark_Docu);
		}
		if (treeNode.icon) icoObj.attr("style", "background:url(" + treeNode.icon + ") 0 0 no-repeat;");
		else icoObj.attr("style", "");
	}
	//设置自定义字体样式
	function setNodeFontCss(setting, treeNode) {
		var aObj = $("#" + treeNode.tId + IDMark_A);
		var fontCss = {};
		if ((typeof setting.fontCss) == "function") {
			fontCss = setting.fontCss(setting.treeObjId, treeNode);
		} else {
			fontCss = setting.fontCss;
		}
		if (fontCss) {
			aObj.css(fontCss);
		}
	}

	//对于button替换class 拼接字符串
	function replaceSwitchClass(obj, newName) {
		if (!obj) return;

		var tmpName = obj.attr("class");
		if (tmpName == undefined) return;
		var tmpList = tmpName.split("_");
		switch (newName) {
		case LineMark_Root:
		case LineMark_Roots:
		case LineMark_Center:
		case LineMark_Bottom:
		case LineMark_NoLine:
			tmpList[1] = newName;
			break;
		case FolderMark_Open:
		case FolderMark_Close:
		case FolderMark_Docu:
			tmpList[2] = newName;
			break;
		}

		obj.attr("class", tmpList.join("_"));
	}
	function replaceIcoClass(obj, newName) {
		if (!obj) return;

		var tmpName = obj.attr("class");
		if (tmpName == undefined) return;
		var tmpList = tmpName.split("_");
		switch (newName) {
		case FolderMark_Open:
		case FolderMark_Close:
		case FolderMark_Docu:
			tmpList[1] = newName;
			break;
		}

		obj.attr("class", tmpList.join("_"));
	}
	
	//添加zTree的按钮控件
	function addTreeDom(setting, treeNode) {
		if (setting.dragStatus == 0) {
			treeNode.isHover = true;
			if (setting.editable) {
				addEditBtn(setting, treeNode);
				addRemoveBtn(setting, treeNode);
			}
			if ((typeof setting.addHoverDom) == "function") {
				setting.addHoverDom(setting.treeObjId, treeNode);
			}
		}
	}
	//删除zTree的按钮控件
	function removeTreeDom(setting, treeNode) {
		treeNode.isHover = false;
		removeEditBtn(treeNode); 
		removeRemoveBtn(treeNode); 
		if ((typeof setting.removeHoverDom) == "function") {
			setting.removeHoverDom(setting.treeObjId, treeNode);
		}
	}
	//删除 编辑、删除按钮
	function removeEditBtn(treeNode) {		
		$("#" + treeNode.tId + IDMark_Edit).unbind().remove();
	}
	function removeRemoveBtn(treeNode) {		
		$("#" + treeNode.tId + IDMark_Remove).unbind().remove();
	}
	function addEditBtn(setting, treeNode) {
		if (treeNode.editNameStatus || $("#" + treeNode.tId + IDMark_Edit).length > 0) {
			return;
		}
		var showEdit_RenameBtn = setting.edit_renameBtn;
		if (typeof setting.edit_renameBtn == "function") {
			showEdit_RenameBtn = setting.edit_renameBtn(treeNode);
		}
		if (!showEdit_RenameBtn) {
			return;
		}

		var aObj = $("#" + treeNode.tId + IDMark_A);
		var nObj = $("#" + treeNode.tId + IDMark_Span);
		var editStr = "<button type='button' class='edit' id='" + treeNode.tId + IDMark_Edit + "' title='' onfocus='this.blur();' style='display:none;'></button>";
		nObj.after(editStr);
		
		var editBtnObj = $("#" + treeNode.tId + IDMark_Edit);
//		var right = (setting.treeObj.offset().left+ setting.treeObj.width() + setting.treeObj.scrollLeft() - aObj.offset().left - aObj.width() - 2*editBtnObj.width() - 15);
//		if (right < 0) {
//			//如果节点处于tree的最右侧，为避免无法正常操作按钮，则在左侧显示
//			editBtnObj.remove();
//			aObj.prepend(editStr);
//			editBtnObj = $("#" + treeNode.tId + IDMark_Edit);
//		}
		editBtnObj.bind('click', 
			function() {
				var beforeRename = true;
				if ((typeof setting.callback.beforeRename) == "function") beforeRename = setting.callback.beforeRename(setting.treeObjId, treeNode);
				if (beforeRename == false) return;
				removeTreeDom(setting, treeNode);
				editTreeNode(setting, treeNode);
				return false;
			}
		).bind('mousedown',
			function(eventMouseDown) {return true;}
		).show();
	}
	function addRemoveBtn(setting, treeNode) {		
		if (!setting.edit_removeBtn || $("#" + treeNode.tId + IDMark_Remove).length > 0) {
			return;
		}
		var showEdit_RemoveBtn = setting.edit_removeBtn;
		if (typeof setting.edit_removeBtn == "function") {
			showEdit_RemoveBtn = setting.edit_removeBtn(treeNode);
		}
		if (!showEdit_RemoveBtn) {
			return;
		}
		
		var aObj = $("#" + treeNode.tId + IDMark_A);
		var removeStr = "<button type='button' class='remove' id='" + treeNode.tId + IDMark_Remove + "' title='' onfocus='this.blur();' style='display:none;'></button>";
		aObj.append(removeStr);
		
		var removeBtnObj = $("#" + treeNode.tId + IDMark_Remove);
//		var right = (setting.treeObj.offset().left + setting.treeObj.width() - aObj.offset().left - aObj.width() - 1*removeBtnObj.width() - 15);
//		if (right < 0) {
//			//如果节点处于tree的最右侧，为避免无法正常操作按钮，则在左侧显示
//			removeBtnObj.remove();
//			aObj.prepend(removeStr);
//			removeBtnObj = $("#" + treeNode.tId + IDMark_Remove);
//		}
		
		$("#" + treeNode.tId + IDMark_Remove).bind('click', 
			function() {
				var beforeRemove = true;
				if ((typeof setting.callback.beforeRemove) == "function") beforeRemove = setting.callback.beforeRemove(setting.treeObjId, treeNode);
				if (beforeRemove == false) return;
				removeTreeNode(setting, treeNode);
				//触发remove事件
				setting.treeObj.trigger(ZTREE_REMOVE, [setting.treeObjId, treeNode]);
				return false;
			}
		).bind('mousedown',
			function(eventMouseDown) {return true;}
		).show();
	}
	
	//设置check后，父子节点联动关系
	function checkNodeRelation(setting, treeNode) {
		if (setting.checkStyle == Check_Style_Radio) {
			if (treeNode[setting.checkedCol]) {
				if (setting.checkRadioType == Radio_Type_All) {
					for (var i = setting.checkRadioCheckedList.length-1; i >= 0; i--) {
						var pNode = setting.checkRadioCheckedList[i];
						pNode[setting.checkedCol] = false;
						setting.checkRadioCheckedList.splice(i, 1);
						
						setChkClass(setting, $("#" + pNode.tId + IDMark_Check), pNode);
						if (pNode.parentNode != treeNode.parentNode) {
							repairParentChkClassWithSelf(setting, pNode);
						}
					}
					setting.checkRadioCheckedList = setting.checkRadioCheckedList.concat([treeNode]);
				} else {
					var parentNode = (treeNode.parentNode) ? treeNode.parentNode : setting.root;
					for (var son = 0; son < parentNode[setting.nodesCol].length; son++) {
						var pNode = parentNode[setting.nodesCol][son];
						if (pNode[setting.checkedCol] && pNode != treeNode) {
							pNode[setting.checkedCol] = false;
							setChkClass(setting, $("#" + pNode.tId + IDMark_Check), pNode);
						}
					}
				}
			} else if (setting.checkRadioType == Radio_Type_All) {
				for (var i = 0; i < setting.checkRadioCheckedList.length; i++) {
					if (treeNode == setting.checkRadioCheckedList[i]) {
						setting.checkRadioCheckedList.splice(i, 1);
						break;
					}
				}
			}
			
		} else {
			if (treeNode[setting.checkedCol] && setting.checkType.Y.indexOf("s") > -1) {
				setSonNodeCheckBox(setting, treeNode, true);
				repairSonChkClass(setting, treeNode);
			}
			if (treeNode[setting.checkedCol] && setting.checkType.Y.indexOf("p") > -1) {
				setParentNodeCheckBox(setting, treeNode, true);
			}
			if (!treeNode[setting.checkedCol] && setting.checkType.N.indexOf("s") > -1) {
				setSonNodeCheckBox(setting, treeNode, false);
				repairSonChkClass(setting, treeNode);
			}
			if (!treeNode[setting.checkedCol] && setting.checkType.N.indexOf("p") > -1) {
				setParentNodeCheckBox(setting, treeNode, false);
			}
		}
	}
	
	//设置CheckBox的Class类型，主要用于显示子节点是否全部被选择的样式
	function setChkClass(setting, obj, treeNode) {
		if (!obj) return;
		obj.removeClass();
		var chkName = setting.checkStyle + "_" + (treeNode[setting.checkedCol] ? CheckBox_True : CheckBox_False)
			+ "_" + ((treeNode[setting.checkedCol] || setting.checkStyle == Check_Style_Radio) ? (treeNode.check_True_Full? CheckBox_Full:CheckBox_Part) : (treeNode.check_False_Full? CheckBox_Full:CheckBox_Part) );
		chkName = treeNode.checkboxFocus ? chkName + "_" + CheckBox_Focus : chkName;
		obj.addClass(CheckBox_Default);
		obj.addClass(chkName);
	}
	function repairAllChk(setting, checked) {
		if (setting.checkable) {
			for (var son = 0; son < setting.root[setting.nodesCol].length; son++) {
				var treeNode = setting.root[setting.nodesCol][son];
				treeNode[setting.checkedCol] = checked;
				checkNodeRelation(setting, treeNode);
				var checkObj = $("#" + treeNode.tId + IDMark_Check);
				setChkClass(setting, checkObj, treeNode);
				repairParentChkClassWithSelf(setting, treeNode);
			}
		}
	}
	//修正父节点选择的样式
	function repairParentChkClass(setting, treeNode) {
		if (!treeNode || !treeNode.parentNode) return;
		repairChkClass(setting, treeNode.parentNode);
		repairParentChkClass(setting, treeNode.parentNode);
	}	
	function repairParentChkClassWithSelf(setting, treeNode) {
		if (treeNode[setting.nodesCol] && treeNode[setting.nodesCol].length > 0) {
			repairParentChkClass(setting, treeNode[setting.nodesCol][0]);
		} else {
			repairParentChkClass(setting, treeNode);
		}
	}
	//修正子节点选择的样式
	function repairSonChkClass(setting, treeNode) {
		if (!treeNode || !treeNode[setting.nodesCol]) return;
		for (var son = 0; son < treeNode[setting.nodesCol].length; son++) {
			if (treeNode[setting.nodesCol][son][setting.nodesCol]) {
				repairSonChkClass(setting, treeNode[setting.nodesCol][son]);
			}
		}
		repairChkClass(setting, treeNode);
	}	
	function repairChkClass(setting, treeNode) {
		if (!treeNode) return;
		var trueSign = true;
		var falseSign = true;
		if (treeNode[setting.nodesCol]) {
			for (var son = 0; son < treeNode[setting.nodesCol].length; son++) {
				if (setting.checkStyle == Check_Style_Radio && (treeNode[setting.nodesCol][son][setting.checkedCol] || !treeNode[setting.nodesCol][son].check_True_Full)) {
					trueSign = false;
				} else if (setting.checkStyle != Check_Style_Radio && treeNode[setting.checkedCol] && (!treeNode[setting.nodesCol][son][setting.checkedCol] || !treeNode[setting.nodesCol][son].check_True_Full)) {
					trueSign = false;
				} else if (setting.checkStyle != Check_Style_Radio && !treeNode[setting.checkedCol] && (treeNode[setting.nodesCol][son][setting.checkedCol] || !treeNode[setting.nodesCol][son].check_False_Full)) {
					falseSign = false;
				}
				if (!trueSign || !falseSign) break;
			}
		}
		treeNode.check_True_Full = trueSign;
		treeNode.check_False_Full = falseSign;
		var checkObj = $("#" + treeNode.tId + IDMark_Check);
		setChkClass(setting, checkObj, treeNode);
	}

	//点击展开、折叠节点
	function onSwitchNode(event) {
		var setting = settings[event.data.treeObjId];
		var treeNode = event.data.treeNode;
		
		if (treeNode.open) {
			var beforeCollapse = true;
			if ((typeof setting.callback.beforeCollapse) == "function") beforeCollapse = setting.callback.beforeCollapse(setting.treeObjId, treeNode);
			if (beforeCollapse == false) return;
			setting.expandTriggerFlag = true;
			switchNode(setting, treeNode);
		} else {
			var beforeExpand = true;
			if ((typeof setting.callback.beforeExpand) == "function") beforeExpand = setting.callback.beforeExpand(setting.treeObjId, treeNode);
			if (beforeExpand == false) return;
			setting.expandTriggerFlag = true;
			switchNode(setting, treeNode);
		}
	}

	function switchNode(setting, treeNode) {
		if (treeNode.open || (treeNode && treeNode[setting.nodesCol] && treeNode[setting.nodesCol].length > 0)) {
			expandAndCollapseNode(setting, treeNode, !treeNode.open);
		} else if (setting.async && !setting.editable) {
			asyncGetNode(setting, treeNode);
		} else if (treeNode) {
			expandAndCollapseNode(setting, treeNode, !treeNode.open);
		}
	}
	
	function getAccessor(obj,expr){
		var ret,p,prm, i;
		if( typeof expr === 'function') { return expr(obj); }
		ret = obj[expr];
		if(ret===undefined) {
		    if ( typeof expr === 'string' ) {
				prm = expr.split('.');
			}
			try {
				i = prm.length; 
				if( i ) {
					ret = obj;
				    while (ret && i--) {
						p = prm.shift();
						ret = ret[p];
					}
				}
			} catch (e) {}
		}
		return ret;
	}
	
	function asyncGetNode(setting, treeNode) {
		if (treeNode && (treeNode.isAjaxing || !treeNode.isParent)) {
			return;
		}
		if (treeNode) {
			treeNode.isAjaxing = true;
			var icoObj = $("#" + treeNode.tId + IDMark_Icon);
			icoObj.attr("class", "ico_loading");
		}

		var tmpParam = "";
		for (var i = 0; treeNode && i < setting.asyncParam.length; i++) {
			tmpParam += (tmpParam.length > 0 ? "&": "") + setting.asyncParam[i] + "=" + treeNode[setting.asyncParam[i]];
		}
		if (Object.prototype.toString.apply(setting.asyncParamOther) === "[object Array]") {
			for (var i = 0; i < setting.asyncParamOther.length; i += 2) {
				tmpParam += (tmpParam.length > 0 ? "&": "") + setting.asyncParamOther[i] + "=" + setting.asyncParamOther[i + 1];
			}
		} else {
			for (var p in setting.asyncParamOther) {
	            tmpParam += (tmpParam.length > 0 ? "&" : "") + p + "=" + setting.asyncParamOther[p];
			}
		}
		
		var url = setting.asyncUrl;
		if (typeof setting.asyncUrl == "function") {
			url =  setting.asyncUrl(treeNode);
		}

		$.ajax({
			type: "POST",
			url: url,
			data: tmpParam,
			//dataType:'json',
			success: function(msg) {
				//alert(msg);
				var newNodes = msg;
				try {
					
					if (!msg || msg.length == 0) {
						newNodes = [];
					} else if (typeof msg == "string") {
						newNodes = eval("(" + msg + ")");
					} else {
						newNodes = msg;
					}
				} catch(err) {}
				
				if($.isFunction(setting.callback.beforeAsyncSuccess)){
					
					if(setting.callback.beforeAsyncSuccess.call(setting.treeObj,newNodes) == false) return;
				}
				
				newNodes = (setting.asyncDataCol) ? getAccessor(newNodes,setting.asyncDataCol) : newNodes; 
				
				
				setNodeLineIcos(setting, treeNode);
				if (newNodes && newNodes != "") {
					addTreeNodes(setting, treeNode, newNodes, false);
				} else {
					addTreeNodes(setting, treeNode, [], false);
				}
				if (treeNode) treeNode.isAjaxing = undefined;
				setting.treeObj.trigger(ZTREE_ASYNC_SUCCESS, [setting.treeObjId, treeNode, msg]);

			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				setting.expandTriggerFlag = false;
				setNodeLineIcos(setting, treeNode);
				if (treeNode) treeNode.isAjaxing = undefined;
				setting.treeObj.trigger(ZTREE_ASYNC_ERROR, [setting.treeObjId, treeNode, XMLHttpRequest, textStatus, errorThrown]);
			}
		});
	}

	// 展开 或者 折叠 节点下级
	function expandAndCollapseNode(setting, treeNode, expandSign, animateSign, callback) {
		if (!treeNode || treeNode.open == expandSign) {
			if (typeof callback == "function") callback();
			return;
		}
		
		if (setting.expandTriggerFlag) {
			callback = function(){
				if (treeNode.open) {
					//触发expand事件
					setting.treeObj.trigger(ZTREE_EXPAND, [setting.treeObjId, treeNode]);
				} else {
					//触发collapse事件
					setting.treeObj.trigger(ZTREE_COLLAPSE, [setting.treeObjId, treeNode]);
				}
			};
			setting.expandTriggerFlag = false;
		}
		
		var switchObj = $("#" + treeNode.tId + IDMark_Switch);
		var icoObj = $("#" + treeNode.tId + IDMark_Icon);
		var ulObj = $("#" + treeNode.tId + IDMark_Ul);

		if (treeNode.isParent) {
			if (!treeNode.open) {
				replaceSwitchClass(switchObj, FolderMark_Open);
				replaceIcoClass(icoObj, FolderMark_Open);
				treeNode.open = true;
				if (animateSign == false || setting.expandSpeed == "") {
					ulObj.show();
					if (typeof callback == "function") callback();
				} else {
					if (treeNode[setting.nodesCol] && treeNode[setting.nodesCol].length > 0) {
						ulObj.show(setting.expandSpeed, callback);
					} else {
						ulObj.show();
						if (typeof callback == "function") callback();
					}
				}
			} else {
				replaceSwitchClass(switchObj, FolderMark_Close);
				replaceIcoClass(icoObj, FolderMark_Close);
				treeNode.open = false;
				if (animateSign == false || setting.expandSpeed == "") {
					ulObj.hide();
					if (typeof callback == "function") callback();
				} else {
					ulObj.hide(setting.expandSpeed, callback);
				}
			}
		} else {
			if (typeof callback == "function") callback();
		}
	}

	//遍历子节点展开 或 折叠
	function expandCollapseSonNode(setting, treeNode, expandSign, animateSign, callback) {
		var treeNodes = (treeNode) ? treeNode[setting.nodesCol]: setting.root[setting.nodesCol];
		
		//针对动画进行优化,一般来说只有在第一层的时候，才进行动画效果
		var selfAnimateSign = (treeNode) ? false : animateSign;
		if (treeNodes) {
			for (var son = 0; son < treeNodes.length; son++) {
				if (treeNodes[son]) expandCollapseSonNode(setting, treeNodes[son], expandSign, selfAnimateSign);
			}
		}
		//保证callback只执行一次
		expandAndCollapseNode(setting, treeNode, expandSign, animateSign, callback );

	}

	//遍历父节点展开 或 折叠
	function expandCollapseParentNode(setting, treeNode, expandSign, animateSign, callback) {
		//针对动画进行优化,一般来说只有在第一层的时候，才进行动画效果
		if (!treeNode) return;
		if (!treeNode.parentNode) {
			//保证callback只执行一次
			expandAndCollapseNode(setting, treeNode, expandSign, animateSign, callback);
			return ;
		} else {
			expandAndCollapseNode(setting, treeNode, expandSign, animateSign);
		}
		
		if (treeNode.parentNode) {
			expandCollapseParentNode(setting, treeNode.parentNode, expandSign, animateSign, callback);
		}
	}

	//遍历父节点设置checkbox
	function setParentNodeCheckBox(setting, treeNode, value) {
		var checkObj = $("#" + treeNode.tId + IDMark_Check);
		treeNode[setting.checkedCol] = value;
		setChkClass(setting, checkObj, treeNode);
		if (treeNode.parentNode) {
			var pSign = true;
			if (!value) {
				for (var son = 0; son < treeNode.parentNode[setting.nodesCol].length; son++) {
					if (treeNode.parentNode[setting.nodesCol][son][setting.checkedCol]) {
						pSign = false;
						break;
					}
				}
			}
			if (pSign) {
				setParentNodeCheckBox(setting, treeNode.parentNode, value);
			}
		}
	}

	//遍历子节点设置checkbox
	function setSonNodeCheckBox(setting, treeNode, value) {
		if (!treeNode) return;
		var checkObj = $("#" + treeNode.tId + IDMark_Check);
		
		if (treeNode != setting.root) {
			treeNode[setting.checkedCol] = value;
			setChkClass(setting, checkObj, treeNode);
		}
		
		if (!treeNode[setting.nodesCol]) return;
		for (var son = 0; son < treeNode[setting.nodesCol].length; son++) {
			if (treeNode[setting.nodesCol][son]) setSonNodeCheckBox(setting, treeNode[setting.nodesCol][son], value);
		}
	}

	//遍历子节点设置level,主要用于移动节点后的处理
	function setSonNodeLevel(setting, parentNode, treeNode) {
		if (!treeNode) return;
		treeNode.level = (parentNode)? parentNode.level + 1 : 0;
		if (!treeNode[setting.nodesCol]) return;
		for (var son = 0; son < treeNode[setting.nodesCol].length; son++) {
			if (treeNode[setting.nodesCol][son]) setSonNodeLevel(setting, treeNode, treeNode[setting.nodesCol][son]);
		}
	}

	//增加子节点
	function addTreeNodes(setting, parentNode, newNodes, isSilent) {
		if (setting.isSimpleData) {
			newNodes = transformTozTreeFormat(setting, newNodes);
		}
		if (parentNode) {
			//目标节点必须在当前树内
			if (setting.treeObj.find("#" + parentNode.tId).length == 0) return;

			target_switchObj = $("#" + parentNode.tId + IDMark_Switch);
			target_icoObj = $("#" + parentNode.tId + IDMark_Icon);
			target_aObj = $("#" + parentNode.tId + IDMark_A);
			target_ulObj = $("#" + parentNode.tId + IDMark_Ul);

			//处理节点在目标节点的图片、线
			if (!parentNode.open) {
				replaceSwitchClass(target_switchObj, FolderMark_Close);
				replaceIcoClass(target_icoObj, FolderMark_Close);			
				parentNode.open = false;
				target_ulObj.css({
					"display": "none"
				});
			}
			
			//如果目标节点不是父节点，增加树节点展开、关闭事件
			if (!parentNode.isParent) {
				target_switchObj.unbind('click');
				target_switchObj.bind('click',
				function() {
					expandAndCollapseNode(setting, parentNode, !parentNode.open);
				});
				target_aObj.unbind('dblclick');
				target_aObj.bind('dblclick', {
					treeObjId: setting.treeObjId,
					treeNode: parentNode
				},
				onSwitchNode);
			}

			addTreeNodesData(setting, parentNode, newNodes);
			initTreeNodes(setting, parentNode.level + 1, newNodes, parentNode);
			//如果选择某节点，则必须展开其全部父节点
			if (!isSilent) {
				expandCollapseParentNode(setting, parentNode, true);
			}
		} else {
			addTreeNodesData(setting, setting.root, newNodes);
			initTreeNodes(setting, 0, newNodes, null);
		}
	}

	//增加节点数据
	function addTreeNodesData(setting, parentNode, treenodes) {
		if (!parentNode[setting.nodesCol]) parentNode[setting.nodesCol] = [];
		if (parentNode[setting.nodesCol].length > 0) {
			parentNode[setting.nodesCol][parentNode[setting.nodesCol].length - 1].isLastNode = false;
			setNodeLineIcos(setting, parentNode[setting.nodesCol][parentNode[setting.nodesCol].length - 1]);
		}
		parentNode.isParent = true;
		parentNode[setting.nodesCol] = parentNode[setting.nodesCol].concat(treenodes);
	}

	//移动子节点
	function moveTreeNode(setting, targetNode, treeNode, moveType, animateSign) {
		if (targetNode == treeNode) return;
		var oldParentNode = treeNode.parentNode == null ? setting.root: treeNode.parentNode;
		
		var targetNodeIsRoot = (targetNode === null || targetNode == setting.root);
		if (targetNodeIsRoot && targetNode === null) targetNode = setting.root;
		if (targetNodeIsRoot) moveType = MoveType_Inner;
		var targetParentNode = (targetNode.parentNode ? targetNode.parentNode : setting.root);

		if (moveType != MoveType_Before && moveType != MoveType_After) {
			moveType = MoveType_Inner;
		}
		
		//进行数据结构修正
		var tmpSrcIndex = -1;
		var tmpTargetIndex = 0;
		var oldNeighbor = null;
		var newNeighbor = null;
		if (treeNode.isFirstNode) {
			tmpSrcIndex = 0;
			if (oldParentNode[setting.nodesCol].length > 1 ) {
				oldNeighbor = oldParentNode[setting.nodesCol][1];
				oldNeighbor.isFirstNode = true;
			}
		} else if (treeNode.isLastNode) {
			tmpSrcIndex = oldParentNode[setting.nodesCol].length -1;
			oldNeighbor = oldParentNode[setting.nodesCol][tmpSrcIndex - 1];
			oldNeighbor.isLastNode = true;
		} else {
			for (var i = 0; i < oldParentNode[setting.nodesCol].length; i++) {
				if (oldParentNode[setting.nodesCol][i].tId == treeNode.tId) tmpSrcIndex = i;
			}
		}
		if (tmpSrcIndex >= 0) {
			oldParentNode[setting.nodesCol].splice(tmpSrcIndex, 1);
		}
		if (moveType != MoveType_Inner) {
			for (var i = 0; i < targetParentNode[setting.nodesCol].length; i++) {
				if (targetParentNode[setting.nodesCol][i].tId == targetNode.tId) tmpTargetIndex = i;
			}
		}
		var targetIsNewParent = false;
		if (moveType == MoveType_Inner) {
			if (targetNodeIsRoot) {
				//成为根节点，则不操作目标节点数据
				treeNode.parentNode = null;
			} else {
				targetIsNewParent = !targetNode.isParent;
				targetNode.isParent = true;
				treeNode.parentNode = targetNode;
			}
			
			if (!targetNode[setting.nodesCol]) targetNode[setting.nodesCol] = new Array();
			if (targetNode[setting.nodesCol].length > 0) {
				newNeighbor = targetNode[setting.nodesCol][targetNode[setting.nodesCol].length - 1];
				newNeighbor.isLastNode = false;
			}
			targetNode[setting.nodesCol].splice(targetNode[setting.nodesCol].length, 0, treeNode);
			treeNode.isLastNode = true;
			treeNode.isFirstNode = (targetNode[setting.nodesCol].length == 1);
		} else if (targetNode.isFirstNode && moveType == MoveType_Before) {
			targetParentNode[setting.nodesCol].splice(tmpTargetIndex, 0, treeNode);
			newNeighbor = targetNode;
			newNeighbor.isFirstNode = false;
			treeNode.parentNode = targetNode.parentNode;
			treeNode.isFirstNode = true;
			treeNode.isLastNode = false;
			
		} else if (targetNode.isLastNode && moveType == MoveType_After) {
			targetParentNode[setting.nodesCol].splice(tmpTargetIndex + 1, 0, treeNode);
			newNeighbor = targetNode;
			newNeighbor.isLastNode = false;
			treeNode.parentNode = targetNode.parentNode;
			treeNode.isFirstNode = false;
			treeNode.isLastNode = true;
			
		} else {
			if (moveType == MoveType_Before) {
				targetParentNode[setting.nodesCol].splice(tmpTargetIndex, 0, treeNode);
			} else {
				targetParentNode[setting.nodesCol].splice(tmpTargetIndex + 1, 0, treeNode);
			}
			treeNode.parentNode = targetNode.parentNode;
			treeNode.isFirstNode = false;
			treeNode.isLastNode = false;
		}
		setSonNodeLevel(setting, treeNode.parentNode, treeNode);
		
		//进行HTML结构修正
		var src_switchObj = $("#" + treeNode.tId + IDMark_Switch);
		var src_ulObj = $("#" + treeNode.tId + IDMark_Ul);

		var targetObj;
		var target_switchObj;
		var target_icoObj;
		var target_aObj;
		var target_ulObj;

		if (targetNodeIsRoot) {
			//转移到根节点
			targetObj = setting.treeObj;
			target_ulObj = targetObj;
		} else {
			//转移到子节点
			targetObj = $("#" + targetNode.tId);
			target_switchObj = $("#" + targetNode.tId + IDMark_Switch);
			target_icoObj = $("#" + targetNode.tId + IDMark_Icon);
			target_aObj = $("#" + targetNode.tId + IDMark_A);
			target_ulObj = $("#" + targetNode.tId + IDMark_Ul);
		}
		
		//处理目标节点
		if (moveType == MoveType_Inner) {
			replaceSwitchClass(target_switchObj, FolderMark_Open);
			replaceIcoClass(target_icoObj, FolderMark_Open);
			targetNode.open = true;
			target_ulObj.css({"display":"block"});
			//如果目标节点不是父节点，且不是根，增加树节点展开、关闭事件
			if (targetIsNewParent && !targetNodeIsRoot) {
				target_switchObj.unbind('click');
				target_switchObj.bind('click',
						function() {
					expandAndCollapseNode(setting, targetNode, !targetNode.open);
				});
				target_aObj.unbind('dblclick');
				target_aObj.bind('dblclick', {
					treeObjId: setting.treeObjId,
					treeNode: targetNode
				},
				onSwitchNode);
			}
			target_ulObj.append($("#" + treeNode.tId).detach());
		} else if (moveType == MoveType_Before) {
			targetObj.before($("#" + treeNode.tId).detach());
			
		} else if (moveType == MoveType_After) {
			targetObj.after($("#" + treeNode.tId).detach());
		}

		//处理被移动的节点
		setNodeLineIcos(setting, treeNode);
		
		//处理原节点的父节点
		if (oldParentNode[setting.nodesCol].length < 1) {
			//原所在父节点无子节点
			oldParentNode.isParent = false;
			var tmp_ulObj = $("#" + oldParentNode.tId + IDMark_Ul);
			var tmp_switchObj = $("#" + oldParentNode.tId + IDMark_Switch);
			var tmp_icoObj = $("#" + oldParentNode.tId + IDMark_Icon);
			replaceSwitchClass(tmp_switchObj, FolderMark_Docu);
			replaceIcoClass(tmp_icoObj, FolderMark_Docu);
			tmp_ulObj.css("display", "none");

		} else if (oldNeighbor) {
			//原所在位置需要处理的相邻节点
			setNodeLineIcos(setting, oldNeighbor);
		}
		
		//处理目标节点的相邻节点
		if (newNeighbor) {
			setNodeLineIcos(setting, newNeighbor);
		}
		
		//修正父节点Check状态
		if (setting.checkable) {
			repairChkClass(setting, oldParentNode);
			repairParentChkClassWithSelf(setting, oldParentNode);
			if (oldParentNode != treeNode.parent) 
				repairParentChkClassWithSelf(setting, treeNode);
		}
		
		//移动后，则必须展开新位置的全部父节点
		expandCollapseParentNode(setting, treeNode.parentNode, true, animateSign);
	}
	
	//编辑子节点名称
	function editTreeNode(setting, treeNode) {
		treeNode.editNameStatus = true;
		selectNode(setting, treeNode);
	}

	//删除子节点
	function removeTreeNode(setting, treeNode) {
		var parentNode = treeNode.parentNode == null ? setting.root: treeNode.parentNode;
		if (setting.curTreeNode === treeNode) setting.curTreeNode = null;
		if (setting.curEditTreeNode === treeNode) setting.curEditTreeNode = null;

		$("#" + treeNode.tId).remove();

		//进行数据结构修正
		var tmpSrcIndex = -1;
		for (var i = 0; i < parentNode[setting.nodesCol].length; i++) {
			if (parentNode[setting.nodesCol][i].tId == treeNode.tId) tmpSrcIndex = i;
		}
		if (tmpSrcIndex >= 0) {
			parentNode[setting.nodesCol].splice(tmpSrcIndex, 1);
		}

		//处理原节点的父节点的图标、线
		if (parentNode[setting.nodesCol].length < 1) {
			//原所在父节点无子节点
			parentNode.isParent = false;
			parentNode.open = false;
			var tmp_ulObj = $("#" + parentNode.tId + IDMark_Ul);
			var tmp_switchObj = $("#" + parentNode.tId + IDMark_Switch);
			var tmp_icoObj = $("#" + parentNode.tId + IDMark_Icon);
			replaceSwitchClass(tmp_switchObj, FolderMark_Docu);
			replaceIcoClass(tmp_icoObj, FolderMark_Docu);
			tmp_ulObj.css("display", "none");

		} else if (setting.showLine) {
			//原所在父节点有子节点
			parentNode[setting.nodesCol][parentNode[setting.nodesCol].length - 1].isLastNode = true;
			parentNode[setting.nodesCol][parentNode[setting.nodesCol].length - 1].isFirstNode = (parentNode[setting.nodesCol].length == 1);
			var tmp_ulObj = $("#" + parentNode[setting.nodesCol][parentNode[setting.nodesCol].length - 1].tId + IDMark_Ul);
			var tmp_switchObj = $("#" + parentNode[setting.nodesCol][parentNode[setting.nodesCol].length - 1].tId + IDMark_Switch);
			var tmp_icoObj = $("#" + parentNode[setting.nodesCol][parentNode[setting.nodesCol].length - 1].tId + IDMark_Icon);
			if (parentNode == setting.root) {
				if (parentNode[setting.nodesCol].length == 1) {
					//原为根节点 ，且移动后只有一个根节点
					replaceSwitchClass(tmp_switchObj, LineMark_Root);
				} else {
					var tmp_first_switchObj = $("#" + parentNode[setting.nodesCol][0].tId + IDMark_Switch);
					replaceSwitchClass(tmp_first_switchObj, LineMark_Roots);
					replaceSwitchClass(tmp_switchObj, LineMark_Bottom);
				}

			} else {
				replaceSwitchClass(tmp_switchObj, LineMark_Bottom);
			}

			tmp_ulObj.removeClass(LineMark_Line);
		}
	}

	//根据 tId 获取 节点的数据对象
	function getTreeNodeByTId(setting, treeId) {
		return getTreeNodeByParam(setting, setting.root[setting.nodesCol], "tId", treeId);
	}
	//根据唯一属性 获取 节点的数据对象
	function getTreeNodeByParam(setting, treeNodes, key, value) {
		if (!treeNodes || !key) return null;
		for (var i = 0; i < treeNodes.length; i++) {
			if (treeNodes[i][key] == value) {
				return treeNodes[i];
			}
			var tmp = getTreeNodeByParam(setting, treeNodes[i][setting.nodesCol], key, value);
			if (tmp) return tmp;
		}
		return null;
	}
	//根据属性 获取 节点的数据对象集合
	function getTreeNodesByParam(setting, treeNodes, key, value) {
		if (!treeNodes || !key) return [];
		var result = [];
		for (var i = 0; i < treeNodes.length; i++) {
			if (treeNodes[i][key] == value) {
				result.push(treeNodes[i]);
			}
			result = result.concat(getTreeNodesByParam(setting, treeNodes[i][setting.nodesCol], key, value));
		}
		return result;
	}

	//取消之前选中节点状态
	function cancelPreSelectedNode(setting) {
		if (setting.curTreeNode) {
			$("#" + setting.curTreeNode.tId + IDMark_A).removeClass(Class_CurSelectedNode);
			$("#" + setting.curTreeNode.tId + IDMark_Span).text(setting.curTreeNode[setting.nameCol]);
			removeTreeDom(setting, setting.curTreeNode);
			setting.curTreeNode = null;
		}
	}
	//取消之前编辑节点状态
	function cancelPreEditNode(setting) {
		if (setting.curEditTreeNode) {
			$("#" + setting.curEditTreeNode.tId + IDMark_A).removeClass(Class_CurSelectedNode_Edit);
			$("#" + setting.curEditTreeNode.tId + IDMark_Input).unbind();
			$("#" + setting.curEditTreeNode.tId + IDMark_Span).text(setting.curEditTreeNode[setting.nameCol]);
			setting.curEditTreeNode.editNameStatus = false;
			setting.curEditTreeNode = null;
		}
	}
	
	//设置节点为当前选中节点
	function selectNode(setting, treeNode) {
		if (setting.curTreeNode == treeNode && !treeNode.editNameStatus) return;
		
		cancelPreSelectedNode(setting);	
		cancelPreEditNode(setting);
			
		if (setting.editable && treeNode.editNameStatus) {
			$("#" + treeNode.tId + IDMark_Span).html("<input type=text class='rename' id='" + treeNode.tId + IDMark_Input + "'>");
			
			var inputObj = $("#" + treeNode.tId + IDMark_Input);
			inputObj.attr("value", treeNode[setting.nameCol]);
			inputObj.focus();
			setCursorPosition(inputObj.get(0), treeNode[setting.nameCol].length);
			
			//拦截A的click dblclick监听
			inputObj.bind('blur', function(event) {
				editNameOver(this.value, setting, treeNode);
			}).bind('keypress', function(event) {
				if (event.keyCode=="13") {
					editNameOver(this.value, setting, treeNode);
				}
			}).bind('click', function(event) {
				return false;
			}).bind('dblclick', function(event) {
				return false;
			});
			
			$("#" + treeNode.tId + IDMark_A).addClass(Class_CurSelectedNode_Edit);
			setting.curEditTreeNode = treeNode;
		} else {
			$("#" + treeNode.tId + IDMark_A).addClass(Class_CurSelectedNode);
		}
		addTreeDom(setting, treeNode);
		setting.curTreeNode = treeNode;
	}
	
	//编辑名称结束
	function editNameOver(newName, setting, treeNode) {
		treeNode[setting.nameCol] = newName;
		//触发rename事件
		setting.treeObj.trigger(ZTREE_RENAME, [setting.treeObjId, treeNode]);
		selectNode(setting, treeNode);
	}
	
	//获取全部 checked = true or false 的节点集合
	function getTreeCheckedNodes(setting, treeNodes, checked) {
		if (!treeNodes) return [];
		var results = [];
		for (var i = 0; i < treeNodes.length; i++) {
			if (treeNodes[i][setting.checkedCol] == checked) {
				results = results.concat([treeNodes[i]]);
			}
			var tmp = getTreeCheckedNodes(setting, treeNodes[i][setting.nodesCol], checked);
			if (tmp.length > 0) results = results.concat(tmp);
		}
		return results;
	}
	
	//获取全部 被修改Check状态 的节点集合
	function getTreeChangeCheckedNodes(setting, treeNodes) {
		if (!treeNodes) return [];
		var results = [];
		for (var i = 0; i < treeNodes.length; i++) {
			if (treeNodes[i][setting.checkedCol] != treeNodes[i].checkedOld) {
				results = results.concat([treeNodes[i]]);
			}
			var tmp = getTreeChangeCheckedNodes(setting, treeNodes[i][setting.nodesCol]);
			if (tmp.length > 0) results = results.concat(tmp);
		}
		return results;
	}
	
	//简要数据转换为标准JSON数组
	function transformTozTreeFormat(setting, simpleTreeNodes) {
		var key = setting.treeNodeKey;
		var parentKey = setting.treeNodeParentKey;
		if (!key || key=="" || !simpleTreeNodes) return [];
		
		if (Object.prototype.toString.apply(simpleTreeNodes) === "[object Array]") {
			var r = [];
			var tmpMap = [];
			for (var i=0; i<simpleTreeNodes.length; i++) {
				tmpMap[simpleTreeNodes[i][key]] = simpleTreeNodes[i];
			}
			for (var i=0; i<simpleTreeNodes.length; i++) {
				if (simpleTreeNodes[i][parentKey] && tmpMap[simpleTreeNodes[i][parentKey]]) {
					if (!tmpMap[simpleTreeNodes[i][parentKey]][setting.nodesCol])
						tmpMap[simpleTreeNodes[i][parentKey]][setting.nodesCol] = [];
					tmpMap[simpleTreeNodes[i][parentKey]][setting.nodesCol].push(simpleTreeNodes[i]);
				} else {
					r.push(simpleTreeNodes[i]);
				}
			}
			return r;
		} else {
			return [simpleTreeNodes];
		}
	}
	
	//标准JSON zTreeNode 数组转换为普通Array简要数据
	function transformToArrayFormat(setting, treeNodes) {
		if (!treeNodes) return [];
		var r = [];
		if (Object.prototype.toString.apply(treeNodes) === "[object Array]") {
			for (var i=0; i<treeNodes.length; i++) {
				r.push(treeNodes[i]);
				if (treeNodes[i][setting.nodesCol])
					r = r.concat(transformToArrayFormat(setting, treeNodes[i][setting.nodesCol]));
			}
		} else {
			r.push(treeNodes);
			if (treeNodes[setting.nodesCol])
				r = r.concat(transformToArrayFormat(setting, treeNodes[setting.nodesCol]));
		}
		return r;
	}

	function zTreePlugin(){
		return {
			container:null,
			setting:null,

			init: function(obj) {
				this.container = obj;
				this.setting = settings[obj.attr("id")];
				return this;
			},

			refresh : function() {
				this.setting.treeObj.empty();
				this.setting.curTreeNode = null;
				this.setting.curEditTreeNode = null;
				this.setting.dragStatus = 0;
				this.setting.dragNodeShowBefore = false;
				this.setting.checkRadioCheckedList = [];
				zTreeId = 0;
				initTreeNodes(this.setting, 0, this.setting.root[this.setting.nodesCol]);
			},

			setEditable : function(editable) {
				this.setting.editable = editable;
				return this.refresh();
			},
			
			transformTozTreeNodes : function(simpleTreeNodes) {
				return transformTozTreeFormat(this.setting, simpleTreeNodes);
			},
			
			transformToArray : function(treeNodes) {
				return transformToArrayFormat(this.setting, treeNodes);
			},

			getNodes : function() {
				return this.setting.root[this.setting.nodesCol];
			},

			getSelectedNode : function() {
				return this.setting.curTreeNode;
			},

			getCheckedNodes : function(selected) {
				selected = (selected != false);
				return getTreeCheckedNodes(this.setting, this.setting.root[this.setting.nodesCol], selected);
			},
			
			getChangeCheckedNodes : function() {
				return getTreeChangeCheckedNodes(this.setting, this.setting.root[this.setting.nodesCol]);
			},

			getNodeByTId : function(treeId) {
				
				if (!treeId) return;
				var node = getTreeNodeByTId(this.setting, treeId);
				return node;
			},
			getNodeByParam : function(key, value) {
				if (!key) return;
				return getTreeNodeByParam(this.setting, this.setting.root[this.setting.nodesCol], key, value);
			},
			getNodesByParam : function(key, value) {
				if (!key) return;
				return getTreeNodesByParam(this.setting, this.setting.root[this.setting.nodesCol], key, value);
			},
			
			getNodeIndex : function(treeNode) {
				if (!treeNode) return;
				var parentNode = (treeNode.parentNode == null) ? this.setting.root : treeNode.parentNode;
				for (var i=0; i<parentNode[this.setting.nodesCol].length; i++) {
					if (parentNode[this.setting.nodesCol][i] == treeNode) return i;
				}
				return -1;
			},
			
			getSetting : function() {
				var zTreeSetting = this.setting;
				var setting = {checkType:{}, callback:{}};
				
				var tmp_checkType = zTreeSetting.checkType;
				zTreeSetting.checkType = undefined;
				var tmp_callback = zTreeSetting.callback;
				zTreeSetting.callback = undefined;
				var tmp_root = zTreeSetting.root;
				zTreeSetting.root = undefined;
				
				$.extend(setting, zTreeSetting);
				
				zTreeSetting.checkType = tmp_checkType;				
				zTreeSetting.callback = tmp_callback;				
				zTreeSetting.root = tmp_root;				

				//不能获取root信息
				$.extend(true, setting.checkType, tmp_checkType);
				$.extend(setting.callback, tmp_callback);
				
				return setting;
			},
			
			updateSetting : function(zTreeSetting) {
				if (!zTreeSetting) return;
				var setting = this.setting;
				var treeObjId = setting.treeObjId;
				
				var tmp_checkType = zTreeSetting.checkType;
				zTreeSetting.checkType = undefined;
				var tmp_callback = zTreeSetting.callback;
				zTreeSetting.callback = undefined;
				var tmp_root = zTreeSetting.root;
				zTreeSetting.root = undefined;
				
				$.extend(setting, zTreeSetting);
				
				zTreeSetting.checkType = tmp_checkType;				
				zTreeSetting.callback = tmp_callback;				
				zTreeSetting.root = tmp_root;				
				
				//不提供root信息update
				$.extend(true, setting.checkType, tmp_checkType);
				$.extend(setting.callback, tmp_callback);
				setting.treeObjId = treeObjId;
				setting.treeObj = this.container;
				
			},

			expandAll : function(expandSign) {
				expandCollapseSonNode(this.setting, null, expandSign, true);
			},

			expandNode : function(treeNode, expandSign, sonSign) {
				if (!treeNode) return;

				if (expandSign) {
					//如果展开某节点，则必须展开其全部父节点
					//为了保证效率,展开父节点时不使用动画
					if (treeNode.parentNode) expandCollapseParentNode(this.setting, treeNode.parentNode, expandSign, false);
				}
				if (sonSign) {
					//多个图层同时进行动画，导致产生的延迟很难用代码准确捕获动画最终结束时间
					//因此为了保证准确将节点focus进行定位，则对于js操作节点时，不进行动画
					expandCollapseSonNode(this.setting, treeNode, expandSign, false, function() {
						$("#" + treeNode.tId + IDMark_Icon).focus().blur();
					});
				} else if (treeNode.open != expandSign) {
					switchNode(this.setting, treeNode);
					$("#" + treeNode.tId + IDMark_Icon).focus().blur();
				}
			},

			selectNode : function(treeNode) {
				if (!treeNode) return;

				selectNode(this.setting, treeNode);
				//如果选择某节点，则必须展开其全部父节点
				//多个图层同时进行动画，导致产生的延迟很难用代码准确捕获动画最终结束时间
				//因此为了保证准确将节点focus进行定位，则对于js操作节点时，不进行动画
				if (treeNode.parentNode) {
					expandCollapseParentNode(this.setting, treeNode.parentNode, true, false, function() {
						$("#" + treeNode.tId + IDMark_Icon).focus().blur();
					});
				} else {
					$("#" + treeNode.tId + IDMark_Icon).focus().blur();
				}
			},
			
			cancleSelectedNode : function() {
				this.cancelSelectedNode();
			},
			cancelSelectedNode : function() {
				cancelPreSelectedNode(this.setting);
			},
			
			checkAllNodes : function(checked) {
				repairAllChk(this.setting, checked);
			},
			
			reAsyncChildNodes : function(parentNode, reloadType) {
				if (!this.setting.async) return;
				var isRoot = !parentNode;
				if (isRoot) {
					parentNode = this.setting.root;
				}
				if (reloadType=="refresh") {
					parentNode[this.setting.nodesCol] = [];
					if (isRoot) {
						this.setting.treeObj.empty();
					} else {
						var ulObj = $("#" + parentNode.tId + IDMark_Ul);
						ulObj.empty();
					}
				}
				asyncGetNode(this.setting, isRoot? null:parentNode);
			},

			addNodes : function(parentNode, newNodes, isSilent) {
				if (!newNodes) return;
				if (!parentNode) parentNode = null;
				var xNewNodes = (Object.prototype.toString.apply(newNodes) === "[object Array]")? newNodes: [newNodes];
				addTreeNodes(this.setting, parentNode, xNewNodes, (isSilent==true));
			},
			
			updateNode : function(treeNode, checkTypeFlag) {
				if (!treeNode) return;
				var checkObj = $("#" + treeNode.tId + IDMark_Check);
				if (this.setting.checkable) {
					if (checkTypeFlag == true) checkNodeRelation(this.setting, treeNode);
					setChkClass(this.setting, checkObj, treeNode);
					repairParentChkClassWithSelf(this.setting, treeNode);
				}
				setNodeName(this.setting, treeNode);
				setNodeTarget(treeNode);
				setNodeUrl(this.setting, treeNode);
				setNodeLineIcos(this.setting, treeNode);
				setNodeFontCss(this.setting, treeNode);
			},

			moveNode : function(targetNode, treeNode, moveType) {
				if (!treeNode) return;
				
				if (targetNode && ((treeNode.parentNode == targetNode && moveType == MoveType_Inner) || $("#" + treeNode.tId).find("#" + targetNode.tId).length > 0)) {
					return;
				} else if (!targetNode) {
					targetNode = null;
				}
				moveTreeNode(this.setting, targetNode, treeNode, moveType, false);
			},

			removeNode : function(treeNode) {
				if (!treeNode) return;
				removeTreeNode(this.setting, treeNode);
			}

		};
	};
})(jQuery);

/**
 * @author gykl
 * 需要库文件
 * jquery-ui.js
 * buss.tree.js
 */
(function($,undefined){
	//var zTree;
	$.widget("ui.treeview",{
		options:{
			//Tree 唯一标识，主UL的ID
			treeObjId: "",
			//是否显示CheckBox
			checkable: false,
			//是否在编辑状态
			editable: false,
			//编辑状态是否显示修改按钮
			edit_renameBtn:true,
			//编辑状态是否显示删除节点按钮
			edit_removeBtn:true,
			//是否显示树的线
			showLine: true,
			//当前被选择的TreeNode
			curTreeNode: null,
			//当前正被编辑的TreeNode
			curEditTreeNode: null,
			//是否处于拖拽期间 0: not Drag; 1: doing Drag
			dragStatus: 0,
			dragNodeShowBefore: false,
			//选择CheckBox 或 Radio
			checkStyle: 'checkbox',
			//checkBox点击后影响父子节点设置（checkStyle=Check_Style_Radio时无效） 			
			checkType: {
				"Y": "ps",
				"N": "ps"
			},
			//radio 最大个数限制类型，每一级节点限制 或 整棵Tree的全部节点限制（checkStyle=Check_Style_Box时无效）
			checkRadioType:"all",
			//checkRadioType = Radio_Type_All 时，保存被选择节点的堆栈
			checkRadioCheckedList:[],
			//是否异步获取节点数据
			async: false,
			//获取节点数据的URL地址
			asyncUrl: "",
			//获取数据的熟悉名(new)
			asyncDataCol:"result.data",
			//获取节点数据时，必须的数据名称，例如：id、name
			asyncParam: [],
			//其它参数
			asyncParamOther: [],
			//简单Array数组转换为JSON嵌套数据参数
			isSimpleData: false,
			treeNodeKey: "",
			treeNodeParentKey: "",
			hasChildKey:"hasChild",
			//用户自定义名称列
			nameCol: "name",
			//用户自定义子节点列
			nodesCol: "nodes", 
			//用户自定义checked列
			checkedCol: "checked", 
			//折叠、展开特效速度
			expandSpeed: "fast",
			//折叠、展开Trigger开关
			expandTriggerFlag:false,
			//hover 增加按钮接口
			addHoverDom:null,
			//hover 删除按钮接口
			removeHoverDom:null,
			//永久自定义显示控件方法
			addDiyDom:null,
			//字体个性化样式接口
			fontCss:{},
			
			root: {
				isRoot: true,
				nodes: []
			},
			//event Function
			callback: {
				beforeClick:null,
				beforeRightClick:null,
				beforeMouseDown:null,
				beforeMouseUp:null,
				beforeChange:null,
				beforeDrag:null,
				beforeDrop:null,
				beforeRename:null,
				beforeRemove:null,
				beforeExpand:null,
				beforeCollapse:null,				
				nodeCreated:null,
				click:null,
				rightClick:null,
				mouseDown:null,
				mouseUp:null,
				change:null,
				drag:null,
				drop:null,
				rename:null,
				remove:null,
				expand:null,
				collapse:null,
				asyncSuccess:null,
				asyncError:null
			}			
		},
		_init:function(){
			
			this.element.addClass("tree");
			this.zTree = this.element.zTree(this.options,this.options.treeData);
	
		},
		getSelectedNode:function(){
			var node = this.zTree.getSelectedNode();
			return node;
		},
		getNodeByTId:function(tId){
			var node = this.zTree.getNodeByTId(tId);
			return node;
		},
		getNodeByParam:function(key,value){		
			//alert(this.zTree.length);
			var node = this.zTree.getNodeByParam(key,value);
			//alert($.trim(node.length));
			return node;
		},
		getNodesByParam:function(key,value){
			var node = this.zTree.getNodesByParam(key,value);
			return node;
		},
		getNodeIndex:function(treeNode){
			var index = this.zTree.getNodeIndex(treeNode);
			return index;
		},
		getNodes:function(){
			var nodes = this.zTree.getNodes();
			return nodes;
		},
		//获取选中或未选中的节点信息
		getCheckedNodes:function(checked){
			var nodes = this.zTree.getCheckedNodes(checked);
			return nodes;
		},
		getSetting:function(){
			return this.zTree.getSetting();
		},
		//将Array格式转换为zTree使用的标准格式,
		//使用此方法，请务必设置节点唯一标识属性名称 treeNodeKey 和 父节点唯一标识属性名称 treeNodeParentKey，并且让数据满足父子关系，注意：简单 Array 数据中必须要让父节点在子节点之前。
		transformTozTreeNodes:function(simpleTreeNodes){
			var nodes = this.zTree.transformTozTreeNodes(simpleTreeNodes);
			return nodes;
		},
		//将 zTree 使用的标准格式转换为简单 Array 格式，便于将数据返回给后台 。（简单遍历 Array 就能得到全部节点）
		transformToArray:function(treeNodes){
			var nodeArr = this.zTree.transformToArray(treeNodes);
			return nodeArr;
		},
		//在指定节点下增加子节点。
		//请通过 zTree 核心函数 zTree(setting, [zTreeNodes]) 运行后，返回的 zTreePlugin 对象执行此方法
		//指定的父节点，如果增加根节点，请设置 parentNode 为 null 即可
		addNodes:function(parentNode,newNodes,isSilent){
			var nodes = this.zTree.addNodes(parentNode,newNodes,isSilent);
			return nodes;
		},
		//让 zTree 展开全部节点。
		//展开 (true) 或 折叠 (false) 标识
		expandAll:function(expandSign){
			this.zTree.expandAll(expandSign);
		},
		expandNode:function(treeNode,expandSign,sonSign){
			this.zTree.expandNode(treeNode,expandSign,sonSign);
		},
		//将某节点移动到其他节点下。
		//targetNode:指定移动到的目标节点 JSON 数据，如果移入根节点，请设置 targetNode 为 null 即可
		//treeNode:指定被移动的节点 JSON 数据
		//moveType:"inner"：成为子节点（默认值），"before"：成为同级前一个节点，"after"：成为同级后一个节点
		moveNode:function(targetNode,treeNode,moveType){
			this.zTree.moveNode(targetNode,treeNode,moveType);
		},
		//刷新zTree
		refresh:function(){
			this.zTree.refresh();
		},
		//删除指定节点
		removeNode:function(treeNode){
			this.zTree.removeNode(treeNode);
		},
		//选中指定节点
		selectNode:function(treeNode){
			this.zTree.selectNode(treeNode);
		},
		//在 checkable 为 true 时，设置全部节点的选中状态。
		//true：全部选中；false：全部取消选中
		checkAllNodes:function(checked){
			this.zTree.checkAllNodes(checked);
		},
		//设置 zTree 是否为可拖拽的编辑状态。
		setEditable:function(editable){
			this.zTree.setEditable(true);
		},
		//将选中的节点设置为未被选中状态
		cancelSelectedNode:function(){
			this.zTree.cancelSelectedNode();
		},
		//更新某节点数据，主要用于该节点显示属性的更新。
		updateNode:function(treeNode,checkTypeFlag){
			this.zTree.updateNode(treeNode,checkTypeFlag);
		},
		//更新Tree当前配置信息,根据options的值进行更新
		updateSetting:function(){
			this.zTree.updateSetting(this.options);
		},
		//指定父节点进行异步加载子节点（已经加载过的父节点可反复使用此方法重新加载）。
		//reloadType = "refresh" 时，表明清空后重新加载，否则进行追加子节点处理。
		reAsyncChildNodes:function(parentNode,reloadType){
			
			this.zTree.reAsyncChildNodes(parentNode,reloadType);
		},
		//获取当前节点的前一个节点
		getPreTreeNode:function(treeNode){
			if(treeNode.isFirstNode) return null;
			var nodes = treeNode.parentNode ? treeNode.parentNode.nodes : this.zTree.getNodes();
			var preNode = null;
			for(var i = 0;i < nodes.length;i++){
				if(nodes[i] == treeNode){
					return preNode;
				}
				preNode = nodes[i];				
			}
			return preNode;
		},
		//获取指定节点的下一个节点
		getNextTreeNode:function(treeNode){
			if(treeNode.isLastNode) return null;
			var nodes = treeNode.parentNode ? treeNode.parentNode.nodes:this.zTree.getNodes();
			for(var i = 0;i < nodes.length;i++){
				if(nodes[i] == treeNode){
					return nodes[i + 1];
				}
			}
		},
		//移动treeNode
		moveTreeNode:function(srcNode,move){		
			var moveType = "inner";
			var targetNode = "";
			if(move == "up"){
				moveType = "before";
				targetNode = this.getPreTreeNode(srcNode);
			}else if(move=="down"){
				moveType = "after";
				targetNode = this.getNextTreeNode(srcNode);
			}else if(move == "left"){
				moveType = "after";
				targetNode = srcNode.parentNode;
			}else if(move == "right"){
				moveType = "inner";
				targetNode = this.getPreTreeNode(srcNode);				
			}
			if(srcNode && targetNode){
				this.zTree.moveNode(targetNode,srcNode,moveType);
			}
			this.selectNode(srcNode);
			return "";
		}
		
	})
})(jQuery);


/*!
 * jQuery Form Plugin
 * version: 2.75 (20-MAY-2011)
 * @requires jQuery v1.3.2 or later
 *
 * Examples and documentation at: http://malsup.com/jquery/form/
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
;(function($) {

/*
	Usage Note:
	-----------
	Do not use both ajaxSubmit and ajaxForm on the same form.  These
	functions are intended to be exclusive.  Use ajaxSubmit if you want
	to bind your own submit handler to the form.  For example,

	$(document).ready(function() {
		$('#myForm').bind('submit', function(e) {
			e.preventDefault(); // <-- important
			$(this).ajaxSubmit({
				target: '#output'
			});
		});
	});

	Use ajaxForm when you want the plugin to manage all the event binding
	for you.  For example,

	$(document).ready(function() {
		$('#myForm').ajaxForm({
			target: '#output'
		});
	});

	When using ajaxForm, the ajaxSubmit function will be invoked for you
	at the appropriate time.
*/

/**
 * ajaxSubmit() provides a mechanism for immediately submitting
 * an HTML form using AJAX.
 */
$.fn.ajaxSubmit = function(options) {
	// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
	if (!this.length) {
		log('ajaxSubmit: skipping submit process - no element selected');
		return this;
	}

	if (typeof options == 'function') {
		options = { success: options };
	}

	var action = this.attr('action');
	var url = (typeof action === 'string') ? $.trim(action) : '';
	url = url || window.location.href || '';
	if (url) {
		// clean url (don't include hash vaue)
		url = (url.match(/^([^#]+)/)||[])[1];
	}

	options = $.extend(true, {
		url:  url,
		success: $.ajaxSettings.success,
		type: this[0].getAttribute('method') || 'GET', // IE7 massage (see issue 57)
		iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
	}, options);

	// hook for manipulating the form data before it is extracted;
	// convenient for use with rich editors like tinyMCE or FCKEditor
	var veto = {};
	this.trigger('form-pre-serialize', [this, options, veto]);
	if (veto.veto) {
		log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
		return this;
	}

	// provide opportunity to alter form data before it is serialized
	if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
		log('ajaxSubmit: submit aborted via beforeSerialize callback');
		return this;
	}

	var n,v,a = this.formToArray(options.semantic);
	if (options.data) {
		options.extraData = options.data;
		for (n in options.data) {
			if(options.data[n] instanceof Array) {
				for (var k in options.data[n]) {
					a.push( { name: n, value: options.data[n][k] } );
				}
			}
			else {
				v = options.data[n];
				v = $.isFunction(v) ? v() : v; // if value is fn, invoke it
				a.push( { name: n, value: v } );
			}
		}
	}

	// give pre-submit callback an opportunity to abort the submit
	if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
		log('ajaxSubmit: submit aborted via beforeSubmit callback');
		return this;
	}

	// fire vetoable 'validate' event
	this.trigger('form-submit-validate', [a, this, options, veto]);
	if (veto.veto) {
		log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
		return this;
	}

	var q = $.param(a);

	if (options.type.toUpperCase() == 'GET') {
		options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
		options.data = null;  // data is null for 'get'
	}
	else {
		options.data = q; // data is the query string for 'post'
	}

	var $form = this, callbacks = [];
	if (options.resetForm) {
		callbacks.push(function() { $form.resetForm(); });
	}
	if (options.clearForm) {
		callbacks.push(function() { $form.clearForm(); });
	}

	// perform a load on the target only if dataType is not provided
	if (!options.dataType && options.target) {
		var oldSuccess = options.success || function(){};
		callbacks.push(function(data) {
			var fn = options.replaceTarget ? 'replaceWith' : 'html';
			$(options.target)[fn](data).each(oldSuccess, arguments);
		});
	}
	else if (options.success) {
		callbacks.push(options.success);
	}

	options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
		var context = options.context || options;   // jQuery 1.4+ supports scope context 
		for (var i=0, max=callbacks.length; i < max; i++) {
			callbacks[i].apply(context, [data, status, xhr || $form, $form]);
		}
	};

	// are there files to upload?
	var fileInputs = $('input:file', this).length > 0;
	var mp = 'multipart/form-data';
	var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);

	// options.iframe allows user to force iframe mode
	// 06-NOV-09: now defaulting to iframe mode if file input is detected
   if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
	   // hack to fix Safari hang (thanks to Tim Molendijk for this)
	   // see:  http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
	   if (options.closeKeepAlive) {
		   $.get(options.closeKeepAlive, fileUpload);
		}
	   else {
		   fileUpload();
		}
   }
   else {
		$.ajax(options);
   }

	// fire 'notify' event
	this.trigger('form-submit-notify', [this, options]);
	return this;


	// private function for handling file uploads (hat tip to YAHOO!)
	function fileUpload() {
		var form = $form[0];

		if ($(':input[name=submit],:input[id=submit]', form).length) {
			// if there is an input with a name or id of 'submit' then we won't be
			// able to invoke the submit fn on the form (at least not x-browser)
			alert('Error: Form elements must not have name or id of "submit".');
			return;
		}
		
		var s = $.extend(true, {}, $.ajaxSettings, options);
		s.context = s.context || s;
		var id = 'jqFormIO' + (new Date().getTime()), fn = '_'+id;
		var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ s.iframeSrc +'" />');
		var io = $io[0];

		$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });

		var xhr = { // mock object
			aborted: 0,
			responseText: null,
			responseXML: null,
			status: 0,
			statusText: 'n/a',
			getAllResponseHeaders: function() {},
			getResponseHeader: function() {},
			setRequestHeader: function() {},
			abort: function(status) {
				var e = (status === 'timeout' ? 'timeout' : 'aborted');
				log('aborting upload... ' + e);
				this.aborted = 1;
				$io.attr('src', s.iframeSrc); // abort op in progress
				xhr.error = e;
				s.error && s.error.call(s.context, xhr, e, e);
				g && $.event.trigger("ajaxError", [xhr, s, e]);
				s.complete && s.complete.call(s.context, xhr, e);
			}
		};

		var g = s.global;
		// trigger ajax global events so that activity/block indicators work like normal
		if (g && ! $.active++) {
			$.event.trigger("ajaxStart");
		}
		if (g) {
			$.event.trigger("ajaxSend", [xhr, s]);
		}

		if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
			if (s.global) { 
				$.active--;
			}
			return;
		}
		if (xhr.aborted) {
			return;
		}

		var timedOut = 0, timeoutHandle;

		// add submitting element to data if we know it
		var sub = form.clk;
		if (sub) {
			var n = sub.name;
			if (n && !sub.disabled) {
				s.extraData = s.extraData || {};
				s.extraData[n] = sub.value;
				if (sub.type == "image") {
					s.extraData[n+'.x'] = form.clk_x;
					s.extraData[n+'.y'] = form.clk_y;
				}
			}
		}

		// take a breath so that pending repaints get some cpu time before the upload starts
		function doSubmit() {
			// make sure form attrs are set
			var t = $form.attr('target'), a = $form.attr('action');

			// update form attrs in IE friendly way
			form.setAttribute('target',id);
			if (form.getAttribute('method') != 'POST') {
				form.setAttribute('method', 'POST');
			}
			if (form.getAttribute('action') != s.url) {
				form.setAttribute('action', s.url);
			}

			// ie borks in some cases when setting encoding
			if (! s.skipEncodingOverride) {
				$form.attr({
					encoding: 'multipart/form-data',
					enctype:  'multipart/form-data'
				});
			}

			// support timout
			if (s.timeout) {
				timeoutHandle = setTimeout(function() { timedOut = true; cb(true); }, s.timeout);
			}

			// add "extra" data to form if provided in options
			var extraInputs = [];
			try {
				if (s.extraData) {
					for (var n in s.extraData) {
						extraInputs.push(
							$('<input type="hidden" name="'+n+'" value="'+s.extraData[n]+'" />')
								.appendTo(form)[0]);
					}
				}

				// add iframe to doc and submit the form
				$io.appendTo('body');
                io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
				form.submit();
			}
			finally {
				// reset attrs and remove "extra" input elements
				form.setAttribute('action',a);
				if(t) {
					form.setAttribute('target', t);
				} else {
					$form.removeAttr('target');
				}
				$(extraInputs).remove();
			}
		}

		if (s.forceSync) {
			doSubmit();
		}
		else {
			setTimeout(doSubmit, 10); // this lets dom updates render
		}
	
		var data, doc, domCheckCount = 50, callbackProcessed;

		function cb(e) {
			if (xhr.aborted || callbackProcessed) {
				return;
			}
			if (e === true && xhr) {
				xhr.abort('timeout');
				return;
			}
			
			var doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
			if (!doc || doc.location.href == s.iframeSrc) {
				// response not received yet
				if (!timedOut)
					return;
			}
            io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);

			var ok = true;
			try {
				if (timedOut) {
					throw 'timeout';
				}

				var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
				log('isXml='+isXml);
				if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) {
					if (--domCheckCount) {
						// in some browsers (Opera) the iframe DOM is not always traversable when
						// the onload callback fires, so we loop a bit to accommodate
						log('requeing onLoad callback, DOM not available');
						setTimeout(cb, 250);
						return;
					}
					// let this fall through because server response could be an empty document
					//log('Could not access iframe DOM after mutiple tries.');
					//throw 'DOMException: not available';
				}

				//log('response detected');
				xhr.responseText = doc.body ? doc.body.innerHTML : doc.documentElement ? doc.documentElement.innerHTML : null; 
				xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
				if (isXml)
					s.dataType = 'xml';
				xhr.getResponseHeader = function(header){
					var headers = {'content-type': s.dataType};
					return headers[header];
				};

				var scr = /(json|script|text)/.test(s.dataType);
				if (scr || s.textarea) {
					// see if user embedded response in textarea
					var ta = doc.getElementsByTagName('textarea')[0];
					if (ta) {
						xhr.responseText = ta.value;
					}
					else if (scr) {
						// account for browsers injecting pre around json response
						var pre = doc.getElementsByTagName('pre')[0];
						var b = doc.getElementsByTagName('body')[0];
						if (pre) {
							xhr.responseText = pre.textContent ? pre.textContent : pre.innerHTML;
						}
						else if (b) {
							xhr.responseText = b.innerHTML;
						}
					}			  
				}
				else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
					xhr.responseXML = toXml(xhr.responseText);
				}
				
				data = httpData(xhr, s.dataType, s);
			}
			catch(e){
				log('error caught:',e);
				ok = false;
				xhr.error = e;
				s.error && s.error.call(s.context, xhr, 'error', e);
				g && $.event.trigger("ajaxError", [xhr, s, e]);
			}
			
			if (xhr.aborted) {
				log('upload aborted');
				ok = false;
			}

			// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
			if (ok) {
				s.success && s.success.call(s.context, data, 'success', xhr);
				g && $.event.trigger("ajaxSuccess", [xhr, s]);
			}
			
			g && $.event.trigger("ajaxComplete", [xhr, s]);

			if (g && ! --$.active) {
				$.event.trigger("ajaxStop");
			}
			
			s.complete && s.complete.call(s.context, xhr, ok ? 'success' : 'error');

			callbackProcessed = true;
			if (s.timeout)
				clearTimeout(timeoutHandle);

			// clean up
			setTimeout(function() {
				$io.removeData('form-plugin-onload');
				$io.remove();
				xhr.responseXML = null;
			}, 100);
		}

		var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
			if (window.ActiveXObject) {
				doc = new ActiveXObject('Microsoft.XMLDOM');
				doc.async = 'false';
				doc.loadXML(s);
			}
			else {
				doc = (new DOMParser()).parseFromString(s, 'text/xml');
			}
			return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
		};
		var parseJSON = $.parseJSON || function(s) {
			return window['eval']('(' + s + ')');
		};
		
		var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4
			var ct = xhr.getResponseHeader('content-type') || '',
				xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
				data = xml ? xhr.responseXML : xhr.responseText;

			if (xml && data.documentElement.nodeName === 'parsererror') {
				$.error && $.error('parsererror');
			}
			if (s && s.dataFilter) {
				data = s.dataFilter(data, type);
			}
			if (typeof data === 'string') {
				if (type === 'json' || !type && ct.indexOf('json') >= 0) {
					data = parseJSON(data);
				} else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
					$.globalEval(data);
				}
			}
			return data;
		};
	}
};

/**
 * ajaxForm() provides a mechanism for fully automating form submission.
 *
 * The advantages of using this method instead of ajaxSubmit() are:
 *
 * 1: This method will include coordinates for <input type="image" /> elements (if the element
 *	is used to submit the form).
 * 2. This method will include the submit element's name/value data (for the element that was
 *	used to submit the form).
 * 3. This method binds the submit() method to the form for you.
 *
 * The options argument for ajaxForm works exactly as it does for ajaxSubmit.  ajaxForm merely
 * passes the options argument along after properly binding events for submit elements and
 * the form itself.
 */
$.fn.ajaxForm = function(options) {
	// in jQuery 1.3+ we can fix mistakes with the ready state
	if (this.length === 0) {
		var o = { s: this.selector, c: this.context };
		if (!$.isReady && o.s) {
			log('DOM not ready, queuing ajaxForm');
			$(function() {
				$(o.s,o.c).ajaxForm(options);
			});
			return this;
		}
		// is your DOM ready?  http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
		log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
		return this;
	}
	
	return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
		if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
			e.preventDefault();
			$(this).ajaxSubmit(options);
		}
	}).bind('click.form-plugin', function(e) {
		var target = e.target;
		var $el = $(target);
		if (!($el.is(":submit,input:image"))) {
			// is this a child element of the submit el?  (ex: a span within a button)
			var t = $el.closest(':submit');
			if (t.length == 0) {
				return;
			}
			target = t[0];
		}
		var form = this;
		form.clk = target;
		if (target.type == 'image') {
			if (e.offsetX != undefined) {
				form.clk_x = e.offsetX;
				form.clk_y = e.offsetY;
			} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
				var offset = $el.offset();
				form.clk_x = e.pageX - offset.left;
				form.clk_y = e.pageY - offset.top;
			} else {
				form.clk_x = e.pageX - target.offsetLeft;
				form.clk_y = e.pageY - target.offsetTop;
			}
		}
		// clear form vars
		setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
	});
};

// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
$.fn.ajaxFormUnbind = function() {
	return this.unbind('submit.form-plugin click.form-plugin');
};

/**
 * formToArray() gathers form element data into an array of objects that can
 * be passed to any of the following ajax functions: $.get, $.post, or load.
 * Each object in the array has both a 'name' and 'value' property.  An example of
 * an array for a simple login form might be:
 *
 * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
 *
 * It is this array that is passed to pre-submit callback functions provided to the
 * ajaxSubmit() and ajaxForm() methods.
 */
$.fn.formToArray = function(semantic) {
	var a = [];
	if (this.length === 0) {
		return a;
	}

	var form = this[0];
	var els = semantic ? form.getElementsByTagName('*') : form.elements;
	if (!els) {
		return a;
	}
	
	var i,j,n,v,el,max,jmax;
	for(i=0, max=els.length; i < max; i++) {
		el = els[i];
		n = el.name;
		if (!n) {
			continue;
		}

		if (semantic && form.clk && el.type == "image") {
			// handle image inputs on the fly when semantic == true
			if(!el.disabled && form.clk == el) {
				a.push({name: n, value: $(el).val()});
				a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
			}
			continue;
		}

		v = $.fieldValue(el, true);
		if (v && v.constructor == Array) {
			for(j=0, jmax=v.length; j < jmax; j++) {
				a.push({name: n, value: v[j]});
			}
		}
		else if (v !== null && typeof v != 'undefined') {
			a.push({name: n, value: v});
		}
	}

	if (!semantic && form.clk) {
		// input type=='image' are not found in elements array! handle it here
		var $input = $(form.clk), input = $input[0];
		n = input.name;
		if (n && !input.disabled && input.type == 'image') {
			a.push({name: n, value: $input.val()});
			a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
		}
	}
	return a;
};

/**
 * Serializes form data into a 'submittable' string. This method will return a string
 * in the format: name1=value1&amp;name2=value2
 */
$.fn.formSerialize = function(semantic) {
	//hand off to jQuery.param for proper encoding
	return $.param(this.formToArray(semantic));
};

/**
 * Serializes all field elements in the jQuery object into a query string.
 * This method will return a string in the format: name1=value1&amp;name2=value2
 */
$.fn.fieldSerialize = function(successful) {
	var a = [];
	this.each(function() {
		var n = this.name;
		if (!n) {
			return;
		}
		var v = $.fieldValue(this, successful);
		if (v && v.constructor == Array) {
			for (var i=0,max=v.length; i < max; i++) {
				a.push({name: n, value: v[i]});
			}
		}
		else if (v !== null && typeof v != 'undefined') {
			a.push({name: this.name, value: v});
		}
	});
	//hand off to jQuery.param for proper encoding
	return $.param(a);
};

/**
 * Returns the value(s) of the element in the matched set.  For example, consider the following form:
 *
 *  <form><fieldset>
 *	  <input name="A" type="text" />
 *	  <input name="A" type="text" />
 *	  <input name="B" type="checkbox" value="B1" />
 *	  <input name="B" type="checkbox" value="B2"/>
 *	  <input name="C" type="radio" value="C1" />
 *	  <input name="C" type="radio" value="C2" />
 *  </fieldset></form>
 *
 *  var v = $(':text').fieldValue();
 *  // if no values are entered into the text inputs
 *  v == ['','']
 *  // if values entered into the text inputs are 'foo' and 'bar'
 *  v == ['foo','bar']
 *
 *  var v = $(':checkbox').fieldValue();
 *  // if neither checkbox is checked
 *  v === undefined
 *  // if both checkboxes are checked
 *  v == ['B1', 'B2']
 *
 *  var v = $(':radio').fieldValue();
 *  // if neither radio is checked
 *  v === undefined
 *  // if first radio is checked
 *  v == ['C1']
 *
 * The successful argument controls whether or not the field element must be 'successful'
 * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
 * The default value of the successful argument is true.  If this value is false the value(s)
 * for each element is returned.
 *
 * Note: This method *always* returns an array.  If no valid value can be determined the
 *	   array will be empty, otherwise it will contain one or more values.
 */
$.fn.fieldValue = function(successful) {
	for (var val=[], i=0, max=this.length; i < max; i++) {
		var el = this[i];
		var v = $.fieldValue(el, successful);
		if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
			continue;
		}
		v.constructor == Array ? $.merge(val, v) : val.push(v);
	}
	return val;
};

/**
 * Returns the value of the field element.
 */
$.fieldValue = function(el, successful) {
	var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
	if (successful === undefined) {
		successful = true;
	}

	if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
		(t == 'checkbox' || t == 'radio') && !el.checked ||
		(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
		tag == 'select' && el.selectedIndex == -1)) {
			return null;
	}

	if (tag == 'select') {
		var index = el.selectedIndex;
		if (index < 0) {
			return null;
		}
		var a = [], ops = el.options;
		var one = (t == 'select-one');
		var max = (one ? index+1 : ops.length);
		for(var i=(one ? index : 0); i < max; i++) {
			var op = ops[i];
			if (op.selected) {
				var v = op.value;
				if (!v) { // extra pain for IE...
					v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
				}
				if (one) {
					return v;
				}
				a.push(v);
			}
		}
		return a;
	}
	return $(el).val();
};

/**
 * Clears the form data.  Takes the following actions on the form's input fields:
 *  - input text fields will have their 'value' property set to the empty string
 *  - select elements will have their 'selectedIndex' property set to -1
 *  - checkbox and radio inputs will have their 'checked' property set to false
 *  - inputs of type submit, button, reset, and hidden will *not* be effected
 *  - button elements will *not* be effected
 */
$.fn.clearForm = function() {
	return this.each(function() {
		$('input,select,textarea', this).clearFields();
	});
};

/**
 * Clears the selected form elements.
 */
$.fn.clearFields = $.fn.clearInputs = function() {
	return this.each(function() {
		var t = this.type, tag = this.tagName.toLowerCase();
		if (t == 'text' || t == 'password' || tag == 'textarea') {
			this.value = '';
		}
		else if (t == 'checkbox' || t == 'radio') {
			this.checked = false;
		}
		else if (tag == 'select') {
			this.selectedIndex = -1;
		}
	});
};

/**
 * Resets the form data.  Causes all form elements to be reset to their original value.
 */
$.fn.resetForm = function() {
	return this.each(function() {
		// guard against an input with the name of 'reset'
		// note that IE reports the reset function as an 'object'
		if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
			this.reset();
		}
	});
};

/**
 * Enables or disables any matching elements.
 */
$.fn.enable = function(b) {
	if (b === undefined) {
		b = true;
	}
	return this.each(function() {
		this.disabled = !b;
	});
};

/**
 * Checks/unchecks any matching checkboxes or radio buttons and
 * selects/deselects and matching option elements.
 */
$.fn.selected = function(select) {
	if (select === undefined) {
		select = true;
	}
	return this.each(function() {
		var t = this.type;
		if (t == 'checkbox' || t == 'radio') {
			this.checked = select;
		}
		else if (this.tagName.toLowerCase() == 'option') {
			var $sel = $(this).parent('select');
			if (select && $sel[0] && $sel[0].type == 'select-one') {
				// deselect all other options
				$sel.find('option').selected(false);
			}
			this.selected = select;
		}
	});
};

// helper fn for console logging
// set $.fn.ajaxSubmit.debug to true to enable debug logging
function log() {
	if ($.fn.ajaxSubmit.debug) {
		var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
		if (window.console && window.console.log) {
			window.console.log(msg);
		}
		else if (window.opera && window.opera.postError) {
			window.opera.postError(msg);
		}
	}
};

})(jQuery);

/* idTabs ~ Sean Catchpole - Version 2.2 - MIT/GPL */ 
(function(){ 
var dep = {"jQuery":"http://code.jquery.com/jquery-latest.min.js"}; 
var init = function(){  
 
/* Options (in any order): 
 
 start (number|string) 
    Index number of default tab. ex: $(...).idTabs(0) 
    String of id of default tab. ex: $(...).idTabs("tab1") 
    default: class "selected" or index 0 
    Passing null will force it to not select a default tab 
 
 change (boolean) 
    True - Url will change. ex: $(...).idTabs(true) 
    False - Url will not change. ex: $(...).idTabs(false) 
    default: false 
 
 click (function) 
    Function will be called when a tab is clicked. ex: $(...).idTabs(foo) 
    If the function returns true, idTabs will show/hide content (as usual). 
    If the function returns false, idTabs will not take any action. 
    The function is passed four variables: 
      The id of the element to be shown 
      an array of all id's that can be shown 
      the element containing the tabs 
      and the current settings 
 
 selected (string) 
    Class to use for selected. ex: $(...).idTabs(".current") 
    default: ".selected" 
 
 event (string) 
    Event to trigger idTabs on. ex: $(...).idTabs("!mouseover") 
    default: "!click" 
    To bind multiple event, call idTabs multiple times 
      ex: $(...).idTabs("!click").idTabs("!focus") 
 
*/ 
	(function($){ 
		 
		  $.fn.idTabs = function(){ 
		    //Loop Arguments matching options 
		    var s = {}; 
		    for(var i=0; i<arguments.length; ++i) { 
		      var a=arguments[i]; 
		      switch(a.constructor){ 
		        case Object: $.extend(s,a); break; 
		        case Boolean: s.change = a; break; 
		        case Number: s.start = a; break; 
		        case Function: s.click = a; break; 
		        case String: 
		          if(a.charAt(0)=='.') s.selected = a; 
		          else if(a.charAt(0)=='!') s.event = a; 
		          else s.start = a; 
		        break; 
		      } 
		    } 
		 
		    if(typeof s['return'] == "function") //backwards compatible 
		      s.change = s['return']; 
		     
		    return this.each(function(){ $.idTabs(this,s); }); //Chainable 
		  } 
		 
		  $.idTabs = function(tabs,options) { 
		    //Settings 
		    var meta = ($.metadata)?$(tabs).metadata():{}; 
		    var s = $.extend({},$.idTabs.settings,meta,options); 
		 
		    //Play nice 
		    if(s.selected.charAt(0)=='.') s.selected=s.selected.substr(1); 
		    if(s.event.charAt(0)=='!') s.event=s.event.substr(1); 
		    
		    if(s.start==null) s.start=-1; //no tab selected 
		     
		    //Setup Tabs 
		    var showId = function(){ 
		      if($(this).is('.'+s.selected)) 
		        return s.change; //return if already selected 
		      var id = "#"+this.href.split('#')[1]; 
		      var aList = []; //save tabs 
		      var idList = []; //save possible elements 
		      $("a",tabs).each(function(i,o){ 
		        if(this.href.match(/#/)) { 
		          aList.push(this); 
		          idList.push("#"+this.href.split('#')[1]); 
		          $(idList[i]).addClass("divborder");
		        } 
		      }); 
		      if(s.click && !s.click.apply(this,[id,idList,tabs,s])) return s.change; 
		      //Clear tabs, and hide all 
		      for(i in aList) {$(aList[i]).removeClass(s.selected);$(aList[i]).parent().removeClass(s.selectedli);} 
		      for(i in idList) $(idList[i]).hide(); 
		      //Select clicked tab and show content 
		      $(this).addClass(s.selected); 
		      $(this).parent().addClass(s.selectedli); 
		      $(id).show(); 
		      return s.change; //Option for changing url 
		    } 
		 
		    //Bind idTabs 
		    var list = $("a[href*='#']",tabs).unbind(s.event,showId).bind(s.event,showId); 
		    list.each(function(){ $("#"+this.href.split('#')[1]).hide(); }); 
		 
		    //Select default tab 
		    var test=false; 
		    if((test=list.filter('.'+s.selected)).length); //Select tab with selected class 
		    else if(typeof s.start == "number" &&(test=list.eq(s.start)).length); //Select num tab 
		    else if(typeof s.start == "string" //Select tab linking to id 
		         &&(test=list.filter("[href*='#"+s.start+"']")).length); 
		    if(test) { test.removeClass(s.selected);test.parent().removeClass(s.selectedul); test.trigger(s.event); } //Select tab 
		 
		    return s; //return current settings (be creative) 
		  } 
		 
		  //Defaults 
		  $.idTabs.settings = { 
		    start:0, 
		    change:false, 
		    click:null, 
		    selected:".selected", 
		    selectedli:"selectedli",
		    event:"!click" 
		  }; 
		 
		  //Version 
		  $.idTabs.version = "2.2"; 
		 
		  //Auto-run 
		  $(function(){ $(".idTabs").idTabs(); }); 
		 
		})(jQuery); 
		 
		 
		 
		} //init 
		 
		// Check Dependencies 
		var check = function(o,s){ 
		  s = s.split('.'); 
		  while(o && s.length) o = o[s.shift()]; 
		  return o; 
		} 
		 
		// Add Script 
		var head = document.getElementsByTagName("head")[0]; 
		var add = function(url){ 
		  var s = document.createElement("script"); 
		  s.type = "text/javascript"; s.src = url; 
		  head.appendChild(s); 
		} 
		 
		// Save Self 
		var s = document.getElementsByTagName('script'); 
		var src = s[s.length-1].src; 
		 
		// Load Dependencies 
		var ok=true; 
		for(d in dep) { 
		  if(check(this,d)) continue; 
		  ok=false; 
		  add(dep[d]); 
		} if(ok) return init(); 
		 
		// Reload Self 
		add(src); 
		 
		})(); 